Archive

Posts Tagged ‘how-to’

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).

Getting Started with IkaScope WiFi Pen-Oscilloscope, and ScanaQuad SQ50 USB Logic Analyzer & Signal Generator

February 5th, 2018 8 comments

A couple of weeks ago, I received IkaScope WS200 pen-like WiFi oscilloscope, as well as ScanaQuad SQ50 USB logic analyzer & signal generator, and I’ve already checked out the hardware both both in a aforelinked unboxing post. I had also very shortly tried IkaScope with GOLE 10 mini PC, but just to showcase potential use case for a Windows 10 mini PC with an inclined touchscreen display. But at the time I did not really a proper measurement, as it was more to test the mini PC than the oscilloscope itself.

I’ve now had time to test IkaScope desktop program and mobile app in respectively Ubuntu 16.04 and Android 8.0.0, as well as ScanaStudio for ScanaQuad USB device using Ubuntu 16.04 only, since there’s no mobile version of the program. While I’ll focus on Ubuntu and Android, most of the instructions will be valid for Window 10 and Mac OS X for the desktop programs, and iOS for the mobile app. This will be more of a getting started guide / basic tutorial, than a review, as I’ll go through some of the issues I may have come across, and show the basic functions of the program/app.

IkaScope connected to Xiaomi Mi A1 Smartphone – Click to Enlarge

IkaScope with Android and Initial Setup

My original plan was to test the oscilloscope with my computer running Ubuntu 16.04, and then switch to Android. However, my computer is connected to the network via Ethernet, and I don’t have a spare working WiFi dongle anymore. The oscilloscope can also work with Ethernet only devices, as long as WiFi is configured in station mode, but by default it starts in access point mode, so I had to change my plan and instead install IkaScope Android app on my smartphone first.

Click to Enlarge

The app is still shown to be in development / a beta version, but as I did not encounter any critical issues, except at the beginning. To turn on the oscilloscope you have to press the probe tip, and should soon see the white LED blink, meaning some “IkaScopexxxx” access point should be setup and ready to go. However, after several attempts, I failed to find any IKASCOPE ESSID in the list of access point. Based on some recommendations on the Internet, I installed WiFiManager, and lo-and-behold IKDASCOPE-…200-00493 SSID showed up. I could easily connect to it, and since it’s an open network, no password is needed.

Time to launch IkaScope app. First you’ll go through a very short wizard showing the key zones in the app, and then we can tap on the top left corner, and click on Connect. It should then show your IkaScope in AP mode (White). 

While you could just select it, and start measurements like when I did when I played with in in Windows 10, it is recommends to switch to station mode. To do so, tap on the setup/configuration on the right side, which should bring you to the “add a network” page as shown below.

You can add just one, but if you add more, you’ll likely get better coverage. Note that the oscilloscope on supports 2.4 GHz, so your 5 GHz ESSID won’t show up.

Now you can go back, maybe wait for the oscilloscope to turn off, and turn it on again by pressing the tip, and a solid Blue LED should show on the device…

.. STA mode (Blue) icon will have replaced the AP mode (white) icon in the mobile app.

Go back again, and you’ll see IKASCOPE WS200 connected in station mode. The screenshot below also shows “CNX-SOFTWARE_5GHz” ESSID, but that’s the connection used by the phone, not the scope.

I’ll detailed the options about the app into more details in the Ubuntu section as they have the same features, and I could only find some cosmetic differences between the mobile and desktop version. I still used the Android app to measure the 16 MHz clock signal from an Arduino Leonardo clone as shown in the top picture.

You can see a short demo about the measurement below.

IkaScope in Ubuntu 16.04

Now that IkaScope WS200 probe is in station mode, I can use it with my Ethernet connected Ubuntu 16.04 computer.

You’ll find IkaScope desktop program on the company website for Windows (.exe) , Linux, and Mac OS X. In the case of Linux, the program is distributed as a tarball, which you need to extract, before running the installation script:

There’s also a an uninstall.sh script to remove the program if you don’t need it anymore. Note the tools only work on 64-bit x86 platforms (x86-64).
After installation IkaScope can be found in the dash, but if I click on the icon, nothing happens, even after a reboot. So I launched it from the terminal instead:

Just like  in Android, you’ll get through a short “tutorial” at the beginning showing the main parts of the interface. Click on IkaScope icon on the top left corner of the program, and connect to find IkaScope.

My probe was  already setup in Station mode, so all I had to do was to select, but if you are using a computer with WiFi, and WS200 probe is in AP mode, you’ll need to connect to the access point, and ideally change that to station mode as shown in the Android section.

I did the same measurement on Arduino Leonardo board, but without using AUTOSET at first. You could then change the voltage and time resolution and offset as needed, but in most case, you’ll probably want to simply use AUTOSET to let the program automatically select the best settings.


A 16 MHz signal has a 62.5 ns period, so first I used the cursor in TIME mode, and moved A and B to confirm both the period and frequency.

Cursors can also be used for voltage (vertical scale). An easier to check the frequency is to use the Measure menu, which allows to automatically reports frequency, period, width, duty, voltage average/peak-to-peak/rms/max/min, and rising and falling times.

Other options include coupling (DC or AC), and Trigger which can be set to automatic, normal, single, rising / falling / both edges  as shown in the screenshot below.

There’s no math function, but I’ve read the company may implement FFT and other functions in the future. I charged the oscilloscope around two weeks ago, and battery level is still well higher than 50%, even after that review. The company estimates a charge should last around one week with a typical use. That’s because the oscilloscope will automatically turn off if it is not being used.

ScanaQuad SQ50 Logic Analyzer in Ubuntu 16.04

Let’s now move on to ScanaQuad SQ50 USB logic analyzer. We’ll need ScanaStudio program available for Windows, Linux, and Mac OS X. That’s what I had to do to install the program in Ubuntu 16.04:

Contrary to Ikascope program, ScanaStudio will install on both 32-bit and 64-bit x86 operating systems. An uninstall script is also provided.

Again the icon can be found in the Dash, but clicking on it won’t launch the program, so I started from a terminal:

The first time I launched the program I was prompted to update the protocols, which are written in JavaScript, and open source with the code on Github.

Click on Download / Update checked button to have the latest protocols loaded into the program. After that, you should get to the main user interface.

I clicked to create a new workspace, which showed several ScanaQuad “demo” devices, but no way to connect to the actual hardware.

However, after searching in the knowledge base, I found out I may have to use the Device wizard compatibility, which can be accessed from the top right icon, and will start a 5-step wizard asking you to disconnect any SUB serial device – including your ScanaQuad -,and reconnect the ScanQuad.

Everything is pretty self-explanatory, and this step may be needed in either Linux or Mac OS X, but not in Windows. You should now see your ScanaQuad USB logic analyzer listed when creating a new workspace, possibly after a reboot (but not needed here).

I selected ScanaQuad SQ50, and clicked on Create workspace button. The very first time, I had to wait as ScanaStudio updated ScanaQuad firmware, which took around a minute. Your workspace should now be shown with the 4-channel used by the tool and some default configuration.

Click to Enlarge

Since last week I reviewed tinyLIDAR, a board based on STM32L0 MCU + VL53L0X ToF sensor that returns the distance from obstacles up to 2 meters away, and that interfaces with the host processor over I2C, I decided to monitor I2C signals with the device.

Click to Enlarge

I connected the black probe to a ground pin, the green probe to SCL, and the red probe to SDA as shown above.

Click to Enlarge

In ScanaStudio, I set sampling rate to 1 MHz, voltage to 5V, clicked on Add new in the Protocols section, selected I2C from the list, assigned CH 3 (Red) to SDA  and CH 4 (Green) to SDL, and clicked Finish. Finally, I also set a trigger to start capture whenever I2C signals are detected.

Click to Enlarge

Now we can click Start at the top right of the interface to make the program wait for the trigger. Going the “Arduino GUI terminal” for tinyLIDAR board, I press enter to read distance (2 byte) from I2C device with address 0x10.

The command ‘D’ should be 0x44 according the ASCII table, and the distance returned is 120 mm.

Click to Enlarge

Right after pressing enter, ScanaStudio captured the SDA and SCL signal and decoded data with a write and a read command as expected:

  • Write 0x10 with 0x88
  • Read 0x10 with 0x00 and 0x78

I would have expected 0x44 (‘D) in the write command, but for some reasons I have not looked into, the command is shifted by one bit. The read data is however fully as expected as 0x78 converted to 120 mm.

I then made the sensor to face the ceiling in order to get a longer distance and use the two fields.

The terminal reports 1823mm, and the I2C capture show 0x071F distance which indeed converts to 1823 mm. So all good here.

If you’re interested in the other supported protocols, you could check out the aforelinked Github repository, and the screenshot below (correct as of February 5, 2018).

More protocols may eventually be supported, or you could roll your own JavaScript decoder if needed.

ScanaQuad SQ50 Signal Generator in Ubuntu 16.04

ScanaQuad also works as a signal generator using the same ScanaStudio program. Mixed mode is supported too, with two inputs for the logic analyzer, and two outputs for the signal generator. I expected to be able to  easily generate sine waves, square waves, and sawtooth waves, but one you switch to Generator mode, the only two options in the Signal builder section are:

  • Square signal wizard up between 1 Hz and 12.5 MHz (min/max values depend on sampling rate) with with duty cycle slider.

Click to Enlarge

  • Signal builder script

Click to Enlarge

The latter has template with all sort of signal include 1-wire, HDMI-CEC, MODBUS, PWM, SPI, and so on. It also mean you should be able to create seesaw and sine waves, but you may have to work (i.e. write some JavaScript code) for it.

Instead of feeding back the signal to the device in mixed mode, I used SQ50 to generate signals, and WS200 probe for measurement.

  • CH1 generating 12.5 MHz square wave with 25% duty cycle


Not what I would call a neat square signal, and the 25% duty signal is not quite right either due to the distorsion.

  • Let’s lower the frequency to 1 MHz with the same duty cycle.


That’s more like it, although there’s still some noise.

    • CH2 generating FM signals

The waveform looks fairly good, and matches the one defined in ScanaStudio.

I’d like to thank Ikalogic for the opportunity to test their measurement devices. IkaScope WS200 oscilloscope sells for 299 Euros exc. VAT, while ScanaQuad SQ50 goes for 89 Euros exc. VAT, and other USB LA+SG models with better specifications such as SQ200 go for up to 149 Euros.

Getting Started with TinyLIDAR Time-of-Flight Sensor on Arduino and Raspberry Pi

January 30th, 2018 8 comments

TinyLIDAR is an inexpensive and compact board based on STMicro VL53L0X Time-of-Flight (ToF) ranging sensor that allows you to measure distance up to 2 meters using infrared signals, and with up to 60 Hz. Contrary to most other VL52LOX boards, it also includes an STM32L0 micro-controller that takes care of most of the processing, frees up resource on your host board (e.g. Arduino UNO), and should be easier to control thanks to I2C commands.

The project was successfully funded on Indiegogo by close to 600 backers, and the company contacted me to provided a sample of the board, which I have now received, and tested with Arduino (Leonardo), and Raspberry Pi (2).

TinyLIDAR Unboxing

I was expecting a single board, but instead I received a bubble envelop with five small zipped packages.

Click to Enlarge

Opening them up  revealed three TinyLIDAR boards, the corresponding Grove to jumper cables, and a bracket PCB for three TinyLIDAR boards together with headers and screws. So I looks like I received the “3 tinyLiDAR – IGG Special” plus the bracket board that was supposed to be a stretch goal unlocked at $25K (but they only got $23,717). Maybe that’s a good sign for backers, we’ll see.

Click to Enlarge

Due to time constraints, I won’t use the bracket, but only single boards. The brackets can be used with three tinyLIDAR boards using different I2C addresses, and you’ll see an example use with the Follow-me 2 Sketch where the 3 LIDAR boards are mounted on a tilt/pan platform that can track your hand.

Click to Enlarge

The bigger chip on the by is STM32L0 Cortex M0+ microcontroller with the much smaller STMicro VL53L0X laser ToF sensor placed right on top of it on the photo above. There are also a few I/O include the 4-pin I2C Grove connector and through holes, some pogopin for direct UART access, an LED, a reset button, and more, as described in the diagram below.


TinyLIDAR on Arduino

Now, it’s time to play with the board using sample and documentation on a dedicated page.  Refer to this page for the latest versions, as below I’ll link to the versions I used for the review.

To easily evaluate and learn about the platform, the company has made what they call Arduino GUI Terminal sketch to let your control the device from an Arduino board using a serial terminal. https://microelectronicdesign.s3.amazonaws.com/tinyLiDAR_Terminal_GUI_1_1.ino

The company only tested Arduino Uno, but it turns out I don’t have one so I had to use an Arduino Leonardo clone instead, and after initial troubles, and help from my contact at the company (Dinesh), I could use tinyLiDAR_Terminal_GUI_1_24.ino with my boardsince it now supports Arduino Uno, Leonardo, and Mega .If you don’t use Arduino Uno (default), make sure you enable your board accordingly in the code by commenting out the relevant line:

The hardware connections are very easy as you just need to connect the jumper cables to the I2C pins, 5V and GND on the board.

Click to Enlarge

Once this was done I connect a micro USB cable to my computer, and tried to upload the ino sketch file, but it failed to compile. That’s because I forgot to install Arduino I2C Master Library, which can be downloaded here, and you just need to click on Sketch->Include Library->Add .ZIP library, and select the freshly downloaded  I2C_Rev5.zip file to complete the installation. I could then build and upload the program to Arduino Leonardo.

Time to start a serial console using minicom, TeraTerm, Putty or others with 115200 8N1 and no flow control to access the Arduino GUI terminal:

You’ll get a list of command in the terminal, but you may want to read the reference manual to clearly understand each item.

I started with the query command, which worked just fine:

I could also use to read command, but to test accuracy I decided to use a ruler and a small box as shown below.

Click to Enlarge

I tested 5cm and 10 cm:

  • 5cm:

  • 10cm:

Not that good…. But there’s a calibration command as explained in the reference manual:

CD Auto-Calibrate Distance Offset
Perform Offset Distance Calibration on tinyLiDAR.
Before using this calibration command, please set tinyLiDAR to Continuous, High Accuracy mode by issuing
the commands “MC” and “PH”. See example code in Appendix A for details.
ST recommends to use a distance of 100mm to a white target. Therefore, place a white target 100mm away
from tinyLiDAR before running this calibration.
Must specify calibration distance in mm.
The new offset correction distance will be placed in non-volatile memory and used for all subsequent
operations. This calibration takes about 10 seconds to run and the LED will flash slowly during the calibration.
You can reset to our factory defaults by executing the “RESET” command.

So let’s go ahead by placing the board at 10 cm from a white box (OK mine was not exactly white), run MC and PH commands (although it does not look necessary),  before running running CD without parameter to do the actual calibration:

Let’s go back to single step operation (ms) and tinyLIDAR preset (pt), and try the measurements again

  • 5cm:

  • 10cm:

It’s getting better, although the first two steps always seen to be stuck to some previous measurements. I’ve been told it may be due to some buffer in the serial terminal.

Trying some longer distances:

  • 20cm:

  • 30cm:

It’s basically doing the job. If you need more accuracy, longer range, or faster measurements, you can change the mode:

  • PL: long range mode (up to 2m, 33ms)
  • PS: high speed mode (up to 1.2m, 20ms)
  • PH: high accuracy mode (up to 1.2m, 200ms)
  • PT: tinyLiDAR mode (up to 2m, 18ms)

One interesting feature, especially if you run on batteries, is the autonomous mode where the board is configured to automatically check the distance range every X second, and trigger a pulse when within range, without having to send I2C commands from the host, except the initial one. In the Arduino GUI terminal, you can for example run:

From there, you won’t show anything in the Arduino terminal, so you can either monitor the autonomous pin – as shown in the diagram below – with the host board or a multimeter…

… or instead you may consider soldering GND and serial TX pins on tinyLIDAR board, and access the read-only console use a USB to TTL debug board as shown below.

The terminal needs to be set to 115200 7N1 without flow control, and you’ll should an output similar to the one below when you run the A command above:

Just to be extra clear, at this stage I have two serial terminal in my computer:

  • /dev/ttyACM0 connected to Arduino where I can input commands
  • /dev/ttyUSB0 connected directly to tinyLIDAR where I can see debug output (read-only)

If you want to integrate it into your own program, you’ll have to send commands as shown by the Arduino sketch to read distance:

The code above is for Arduino Uno, so if you use Arduino MEGA or Leonardo you’ll need to change the PORT to PORTD, and SCL and SDA to pin 0 and 1 respectively.

TinyLIDAR on Raspberry Pi 2/3

Arduino is cool, but if your project is better suited to Raspberry Pi board, you can also connect tinyLIDAR to the I2C port of Raspberry Pi 2/3, or any other Raspberry Pi boards. The instructions are explained in details on Instructables, also explaining some of the shortcomings of I2C on Raspberry Pi board (lack of clock stretching support, pull up resistors installed). The steps are very details, even suitable to people having never used a Raspberry Pi, so here I’ll go faster focusing on settings specific to tinyLIDAR use.

First you need to scratch the I2C PCB trace on tinyLIDAR with a cutter to disconnect the pull-up resistors since it’s already done on the Raspberry Pi board. Now we can connect tinyLIDAR to the I2C pins, as well as 3.3V and GND.

I used the same Raspbian Stretch Lite image with SSH enabled (/boot/ssh file present) as I did for ANAVI Light pHAT. Now we need to install pigpio in Raspberry Pi as follows:

You’ll also need o run raspi-config to enable I2C.

The next step is optional, but I still recommend it as at the beginning I had trouble finding tinyLIDAR. That’s the step to detect tinyLIDAR I2C address:

We can see 0x10 I2C address is detected, and that’s our tinyLIDAR board. If you don’t have any addresses detected, re-check your connections.

Now that we have confident the hardware is OK, we can install “RPI TinyLIDAR Terminal GUI”:

and launch it with:


From there, it’s the same as in the Arduino terminal GUI, for example read and query commands:

Again the RPi terminal GUI is just for evaluation, but you can study the Python in order to integrate support for tinyLIDAR into your own Python application.

That’s all for this getting started guide.

The crowdfunding campaign is now over, but you can buy TinyLIDAR board directly on MicroElectronic Design website for $24.95.  You’ll also find the bracket board for $4.95 and a pack of 100 mounting screws on that page. Further details may also be found on the product page.

Getting Started with ANAVI Light pHat Starter Kit with RGB LED Strip, Light Sensor

January 21st, 2018 No comments

ANAVI Light pHAT is an expansion board best suited for Raspberry Pi Zero (W/WH) boards, but also working with any other Raspberry Pi boards with a 40-pin header, that can control a 12V RGB LED strip and sensors. The project’s crowdfunding has just been successfully completed on CrowdSupply with 82 pledges, but you can still pre-order the board or kits for $25 and up.

The developer – Leon ANAVI – had sent me a starter kit a little while ago, and this week-end I had time to test the basic functionalities of the board.

The package includes the pHAT board itself, a one meter RGB LED strip, an I2C sensor, and some stickers.

Click to Enlarge

The sensor is based on BH1750 ambient light intensity sensor.

The light pHAT boards include a 4-pin 12V/RGB blue terminal, EEPROM, three I2C connecter, a 3.3V UART connector to access the serial console for debugging / running commands, and a 3-pin PIR sensor header on the left.

Click to Enlarge

The board requires a 12V power source, and the bottom side only comes with a 40-pin female header to connect it to your chosen Raspberry Pi boards.

Click to Enlarge

I decided to go with Raspberry Pi 2 board since I already had installed Raspbian 8 (Jessie), and I had used it for ANAVI Infrared pHAT. Installed is very easy, no soldering required:

  1. Insert the board into the 40-pin RPi header
  2. Insert the RGB LED strip wire into the blue terminal, and tighten with a precision screw drive
  3. Optionally add any I2C sensor or PIR sensor you wish to use in the corresponding I2C/PIR sensor header
  4. Place the RGB LED strip in a “strategic” position

I’m a little late for this, but I wrapped it around Santa Claus’ hat.

Click to Enlarge

We can now switch to software installation for which I followed the instructions on Github. We’ll need Raspbian, and considering the Raspberry Pi foundation had released Debian 9 for RPi since last time I played with the board, I first opted to upgrade from Debian 8 to Debian 9, but after finding it took a very long,  I downloaded and installed Raspbian Stretch Lite instead, wiping out my SD card for a fresh start.

Note that Raspbian now disables SSH by default, so for a headless setup not using the serial connection, you’d need to enable SSH by placing a file named ‘ssh’, without any extension, onto the boot partition of the SD card. (e.g. /boot/ssh). I did that an I could connect over ssh after connecting Ethernet.

Now that we are connected to the Raspberry Pi board via SSH/Terminal/HDMI, we can upgrade the system to the latest version, and install the required packages:

The packages list is a little different from the one in the wiki because by default, Raspbian Lite lacks some packages such as pigpio, which needs to be installed manually. Once it is done let’s run raspi-config:

and go to Interfacing Options to enable I2C (P5) and optionally Serial (P6) if you need to access the board through a serial terminal.

We can now load pigpio daemon, and turn on the red lights:

turning off red lights, turn on blue light:

and turn off blue lights, turn on green lights:

All working good for me, so we can confirm the hardware is working. But you’ll likely want to write your own program to control the LED strip, and to help you out Leon wrote a demo program randomly updating the lights colors.

The program needs WiringPi,  so let’s retrieve the code and build it:

We can now get the sample app written in C language to control the strip with PWM:

Watch a 2-minute demo with the board showing the basic commands above, and demo program.

The demo only controls the RGB LED strip, but none of the sensors. So first let’s see if we can find the light sensor:

I2C address 0x23 is found. Now we can build the sample app also written in C language:

Results with room light off:

Results with room light on:

Results with sensor covered with hand:

The source code for the function to get the luminance value is very short, and easy to understand:

So for example it would be simple to modify the RGB LED demo code to only start the LED strip when the lux value is less than a given value. That’s all for this getting started guide, and it went fairly smoothly in my case just following instructions on Github.

If you want to go further, Leon added Home Assistant support using Hassbian distribution,  and is working on instructions to integrate IKEA GRÖNÖ table lamp with ANAVI Light pHat (Stretch goal).

How to Use Khadas VIM2 Board with VTV Expansion DTV Board as a Live TV Streaming Server

December 18th, 2017 10 comments

Khadas VIM2 is the first and only Amlogic S912 based hobbyist development board on the market, which makes it interesting by itself, but the company also added some interesting features such as an SPI flash for network boot, Wake-on-LAN support, and more. Last month the company sent me a sample of the Khadas VIM2 Basic (2GB RAM/16GB flash) together with VTV Extension DTV Board featuring a DVB-T2/C and DVB-S2 tuner.

I’ve already checkout the hardware and shown how to assemble the kit, so for the second part of the review it seemed like a good idea to use the board as a Live TV streaming server broadcasting satellite, cable or terrestrial TV to devices connected to the local network. At first I wanted to use Linux operating system, because I could have run other Linux server services, but SuperDVB, the company that makes and supports the tuner board, only have Android software for their board.

So I changed plan, and instead used their Android VTV app to stream the video over Gigabit Ethernet. I’ll report my experience setting this all up in this post.

Click to Enlarge

Download & Flash Android firmware to Khadas VIM2 board

First we need to download the latest firmware on Khadas Firmware Resources page. Here you’ll find a little of firmware with names such as VIM2_Nougat_V171028 or VIM2_Nougat_vTV_V171024. The “vTV” string is important here, as the one without do not support the tuner board, so we’ll need one with vTV. So I downloaded VIM2_Nougat_vTV_V171024.7z  Android firmware, and VIM2_Uboot_Nougat_171028.7z “uboot” files from the page. Just make you download the latest version on the website.

The firmware provided works with Amlogic USB Burning Tool Windows software, but the tool is not really user-friendly, and in my case not directly supported as it only runs on Windows. So instead it’s better to flash the firmware to a bootable SD card (backup instructions here) in Ubuntu. If you are using Windows, Burn Card Maker Tool is much easier to use.

If you are using Ubuntu or a Linux distributions, there are a few steps to follow. After inserting you card, locate it with lsblk:

I’m using a 16GB card, so /dev/sdd is the device to so. We’ll need one partition, but my card has none for now:

I’ll use /dev/sdX to refer to the device from now on to avoid potential data loss due to copy/paste gone wrong.

We can create a new primary partition of W95 FAT type with fdisk or (g)parted:

Once it’s done let’s format it with FAT32:

Now we can copy u-boot binary for SD card to specific locations in the storage device:

Now unplug and replug the card to mount it automatically (or mount it with the command line) in order to copy the command and firmware files:

Now we can remove the card from the computer, and insert it into Khadas VIM2 board, and enter upgrade mode, by pressing the power key, pressing and releasing the reset key, wait two or three seconds, before releasing the power key on the board.You should see an Android logo and “Upgrading…” string together with a progress bar, and after a few minutes, the firmware should be flashed successfully.

A look at Android Settings

At this point, we can remove the micro SD card, and reboot the board, and within a few seconds, we’ll get to the (stock) launcher.

Click for Original Size

Several apps are installed including Google Play and MoviePlayer. VTV is the app we’ll use to watch and stream Live TV.

But let’s have a look at some of the settings. I’ve reviewed many Amlogic S912 TV boxes from the popular MINIX NEO U9-H media hub, to the cheap MN12N TV box, or Mecool KIII Pro set-top box with a dual DVB-T2/S2 tuner among other, so I’m not going into the full details, but instead focus on some of the unique features.

Click to Enlarge

The image is based on Android 7.1.2 with Linux 3.14.29, and offers typical features like HDMI CEC or playback settings (HDMI self-adaptation), but if we go into More settings we’ll find some less usual option for the cooling, LED, and WOL.

Click to Enlarge

Cooling fan will allow you to turn on or off fan support, and set either automatic speed, low speed, medium speed, or high speed. LED option allows the user to control the board’s LED behavior such as always on, always off, heartbeat mode, or breather mode.

WOL is used to enable or disable Wake On LAN.

Khadas VIM2 CPU Temperature, Fitting an Heatsink

During my first post, people had concerns about using the board without heatsink, and based on CPU-Z app, CPU temperature is indeed around 76°C in idle mode.

When I watched and streamed live TV, the video did not feel very smooth especially on the display connected to the board, so I decided to fit an heatsink to the board.

I put some thermal grease on Amlogic S912 SoC, the flash and the two RAM chip to the heatsink on top. You may not necessary use such large heatsink, but that’s the only spare one I had. The amount of cooling you need also depends on your application.

With the heatsink, the temperature drops to 58°C (26°C room temperature), but I still had some troubles while watching live TV. So the problem is most probably not temperature related, as reported temperature only climbed to around 62°C while watching and streaming video from VTV app

Install VTV V2 App with IP Streaming Function

This section may not be necessary in the future, as the latest app will be updated in the firmware, but IP Streaming function is new, so I had to download VTV-2017-11-30-IpStreamming.rar, extract it, and manually install VTV-2017-11-30-IpStreamming.apk to the board. It’s now important to reboot the board to avoid version conflict.

At this point we should launch the app, and scan the channels. VTV app is based on DTV app found in Videostrong/Mecool set-top boxes, you can follow the same DVB-T2/DVB-S2 configuration instructions. I connected the tuner to my roof top antenna, so the first time after being asked to scan the channels, I went through DVB-T2 configuration.

That part took me an awful lot of time, as despite having 95 to 100% signal strength, none of the channels would lock. Eventually, the company sent me another tuner board, but it turned out my antenna cable connector had a bad contact or short circuit, as I would only get proper signal when bending the cable. So I disassembled and cleaned up the connector, and everything worked fine. Lesson: high signal strength in DTV/VTV app do not mean you cable / antenna is working fine.

Finally, we can make sure we have the latest app, by pressing the INFO key while watching a channel in order to show service info & version of the app.

APK (V2) is exactly what we want so we can go ahead. There’s a problem with Thai font or encoding, which has been a recurring problem in all Amlogic set-top boxes I’ve tested in the past. Hopefully, this will be fixed one day.

Khadas VIM2 Live TV Streaming

Once we have the channel configured, we can enable IP streaming by pressing the MENU key on the remote control, then DTV preference->IP stream setting.

You can manually set the port between 10,000 and  65,535 (20,000 default), and the app will provide you with the streaming link (e.g. http://192.168.0.114:20000), and the maximum number of client (10). You can use now use this link with a program or app on other devices in the network. I used GoodPlayer app in my Android phone and VLC in computer like I did while streaming video from Zidoo X9S’ HDMI input.

In the demo below, I use three clients: one Android phone, a Ubuntu 16.04 laptop, and my Ubuntu 16.04 desktop PC playing the video from Khadas VIM2 board at the same time.

I think the feature is still beta, so maybe that’s why there are problems while changing channels where the client may not pick up the stream. The live channel in Khadas VIM2 appears not to be quite as smooth as it could be too, again some optimization may likely solve this issue.

A better way to change channels however is to export ip stream list file tvlist.txt in VTV app by pressing the red/audio button on the remote control, which in my location looks as follow:

I copied it to my computer, and renamed it to tvlist.m3u, and you use in VLC to easily switch to the channel of your choice.

Click to Enlarge

Going forward, I think Linux support for the tuner board is unlikely, so people should really focus on Android if they plan to use the board. I’ve asked the company if they planed to release the source code for VTV app or at least an API to let people integrate support into their own app, but I have not received an answer yet.

For end users support for TVHeadEnd would be a bonus, as they’d be able to watch live TV, access the EPG, and change channels right from Kodi running in the client, as it’s now done in products such as U4 Quad Hybrid, U5PVR, or WeTek Play 2.

[Update: answers from company:

  1. Linux is not in their plan now, and they are focus on Android platform.
  2. VTV app can not be made open source due to it being used in other business projects, and there does not seem to be plans an API either
  3. “TVheadend is supported by LibreElec already, for Android platform, we will try to learn it and make it into software if possible.”  See comments below for download link for LibreELEC.

I’d like to thank Khadas (Shenzhen Wesion), and SuperDVB for sending the kit for review and their support getting this to work. Khadas VIM2 Basic board can be purchased on GearBest for $89.99 shipped, and the “VTV Expansion DTV board” for $39.99. You’ll pay a bit less if you take a bundle for a total of $112.98 including shipping ($17 discount) available from the latter link.

NanoPi Duo Quick Start Guide – Ubuntu, Breadboard, Mini Shield & mSATA SSD

October 30th, 2017 13 comments

As far as I know NanoPi Duo is the only quad core ARM Linux development board that can fit on a breadboard. We’ve already seen it’s much smaller than Raspberry Pi Zero, and the company offer a mini shield exposing USB ports, Ethernet, a few I/Os, and an mSATA slot in in NanoPi Duo Starter Kit Review – Part 1: Unboxing and Assembly.

I’ve finally played with it this week-end, and will report what I had to do to blink a LED when connected to breadboard, and my experience using the mini shield with  an mSATA SSD, WiFi connectivity, and cooling under load.

Flashing Ubuntu 16.04.2 firmware image to NanoPi Duo

As with many other Allwinner development boards, you should first check if Armbian is available for the board. NanoPi Duo is not supported, but it’s said to work with Orange Pi Zero image minus support for WiFi. Since the latter is rather important if you’re going to use the board standalone, I instead went with FriendlyELEC’s Ubuntu Xenial image (nanopi-duo_ubuntu-core-xenial_4.11.2_20170908.img.zip) shared on the company’s Wiki.

I flashed the (compressed) image with Etcher – available for Windows, Linux, Mac OS, on a 8GB micro SD card (Sandisk Ultra).

Using NanoPi Duo as a Breadboard-friendly Development Board

Once this is done, insert the micro SD into the board, insert it into a breadboard, and connect your circuit (in my case a 5V LED connected to GPIOG11 via a transistor). Most other breadboard-friendly WiFi boards include either a USB to TLL chip allowing to access the board’ serial console over USB (e.g. ESP32 boards), or firmware that setups the board as an access point for initial configuration (e.g. LinkIt Smart 7688 Duo). So you just need to connect power and you’re good to go.

Click to Enlarge

But NanoPi Duo’s board has no serial to USB chip, and the current firmware does not setup an access point by default, so I’ll need to connect a USB to TLL debug board too, as shown above. I then started minicom with 115200 8N1 configuration, and connected the board to one of the USB port of my computer for power, and the boot worked just fine.  See complete boot log for reference: