OpenCV 3.4.3 + Raspberry Pi 3B+

Follow these steps to install OpenCV 3.4.3 on a Raspberry Pi 3B+:

1) Install these dependencies:

$ sudo apt-get install build-essential cmake pkg-config
$ sudo apt-get install libjpeg-dev libtiff5-dev libjasper-dev libpng12-dev
$ sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
$ sudo apt-get install libxvidcore-dev libx264-dev
$ sudo apt-get install libgtk2.0-dev libgtk-3-dev
$ sudo apt-get install libatlas-base-dev gfortran
$ sudo apt-get install python2.7-dev python3-dev

2) Get OpenCV

$ wget https://github.com/opencv/opencv/archive/3.4.3.zip
$ unzip 3.4.3.zip
$ rm 3.4.3.zip
$ wget https://github.com/opencv/opencv_contrib/archive/3.4.3.zip
$ unzip 3.4.3.zip

3) Build & Install OpenCV
NOTE 1: In the cmake line there is a path to the opencv_contrib modules folder, please replace this path with the correct one for your system.

NOTE 2: The make step will take like 8-10 hours and it will crash several times due to low virtual memory. Luckily it can resume from where it crashes so I kept repeating the make command until it finished.

sudo apt-get install python-pip
pip install numpy
$ cd ~/opencv-3.4.3/
$ mkdir build
$ cd build
$ cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D INSTALL_PYTHON_EXAMPLES=ON -D OPENCV_EXTRA_MODULES_PATH=/home/pi/Desktop/OpenCV/opencv_contrib-3.4.3/modules -D BUILD_EXAMPLES=ON ..
$ make -j4
$ sudo make install
$ sudo ldconfig

4) Confirm OpenCV installation

$ python
>>> import cv2
>>> cv2.__version__
'3.4.3'

5) Voila!

Advertisements

Serial Comms between NodeMCU & Arduino Nano

Here’s how to set up serial comms between a NodeMCU V1 (ESP-12E) and Arduino Nano. Note, you could replace the Nano with any Arduino board but I have only tested with a Nano.

Here are parts required:

Here’s the diagram:

circuitAnd the source code is available here: https://github.com/coytar/Snippets/tree/master/NodeMCU_To_Nano

Good luck! 🙂

 

HTTP GET using Volley

I was making an Android app using Android Studio (3.1.3) which sends a HTTP GET request. The code was very similar to this:

String serverURL = "http://192.168.0.150/main_light/switch";
URL url = new URL(serverURL);
HttpURLConnection connection = null;
try {
    connection = (HttpURLConnection) url.openConnection();
    connection.setRequestMethod("GET");
    BufferedReader in = new BufferedReader(
    new InputStreamReader(con.getInputStream()));
    //Do something with this InputStream
    // handle the response
    int status = connection.getResponseCode();
    // If response is not success
    if (status != 200) {
        throw new IOException("Post failed with error code " + status);
    }
} catch (Exception e) {
    Log.e(TAG,e.toString());
} finally {
     if(connection != null)
         connection.disconnect();
}

The request was never sent. I tried everything but I just couldn’t make it work. However!

I found a solution using Volley (https://developer.android.com/training/volley/simple). This code is in Kotlin but as you can see it is very simple and mostly importantly it works!

val queue = Volley.newRequestQueue(this)
val url = "http://192.168.0.150/main_light/switch"
val stringRequest = StringRequest(Request.Method.GET, url, null, null)
queue.add(stringRequest)

Don’t forget to add these lines to the AndroidManifest.xml file:

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

 

NodeMCU ESP8266 CP1202 Programming (Blink)

This is the tutorial for programming the NodeMCU CP1202 board using the Arduino IDE. The code that will be used is the Blink example. And the board that I’m using looks like this.

Image result for cp1202 nodemcu

Here are the steps I followed:

  1. Install the drivers from https://www.silabs.com/products/development-tools/software/usb-to-uart-bridge-vcp-drivers
  2. Download the ESP8266 board information for Arduino
    1. Open the Arduino IDE
    2. Click on the File menu and then Preferences
    3. In the Additional Boards Manager URLs, enter this: http://arduino.esp8266.com/stable/package_esp8266com_index.json
    4. Click Ok
    5. Click on the Tools menu, click Boards and then click Boards Manager
    6. Wait for it to download the new boards information
    7. Search for ESP8266 and install it
  3. From the Tools menu, select the following:
    1. Board: NodeMCU 1.0 (ESP-12E Module)
    2. Flash Size: 4M (3M SPIFFS)
    3. CPU Frequency: 80MHz
    4. Upload Speed: 115200
    5. Port: (whichever COM port it is)
    6. Erase Flash: Sketch Only
  4. From the File menu, click Examples, click ESP8266 and then click Blink
  5. Compile and download
  6. Voila! 🙂

Binary Counter (updated)

Here’s a simple binary counter using the onboard LEDs on the Mojo V3:

Capture

Source code: https://github.com/coytar/Snippets/tree/master/Lucid/BinaryCounter

UPDATE:
I found an even simpler code:

Capture

Source code: https://github.com/coytar/Snippets/tree/master/Lucid/BinaryCounterV2

ISE 14.7 + Mojo V3

I wanted to play with FPGAs so I bought a Mojo V3 board (https://embeddedmicro.com/products/mojo-v3). (FYI I got cheaper from another site). To use this board you need the Xilinx ISE software which is available for free. Xilinx provides two methods:
1) Download a pre built VM with the ISE software already installed
2) Download the install files and do it your self.

The obvious choice I thought would be option 1. I download the VM from here (https://www.xilinx.com/support/download/index.html/content/xilinx/en/downloadNav/design-tools/14_7-windows.html).

Here’s my quick review of the VM:

  • It uses Oracle Linux 6.4 running Kernel 2.6-32.358 which can’t interface with the Mojo
  • Despite my best efforts I couldn’t change enough settings to make it interface with the Mojo V3. Oracle Linux kept loading the Mojo as ttyUSB0 instead of ttyACM0, and I couldn’t change that.

After that experience I decided to build my own VM but this time use Ubuntu as the base system. I used Ubuntu 16.04 and everything worked beautifully!