MCC 118 – 100kS/s Stackable DAQ HAT For Raspberry Pi

Measurement Computing Corporation (MCC) has released a $99 measurement DAQ (Data acquisition system) HAT for the Raspberry Pi. It is highly optimized for single point and waveform voltage. MCC claims their board allows greater accuracy with high resolution. It has much faster sample rates than many other DAQ HAT add-ons for the Raspberry Pi. The new “MCC 118” provides 8x single-ended, 12-bit, ±10 V analog inputs with sample rates up to 100 kS/s.

MCC 118 with Pi and with four-board stacked configuration
MCC 118 with Pi and with four-board stacked configuration

Maximum of eight MCC HATs can be stacked onto one Raspberry Pi, providing up to 64 channels of data and a maximum total throughput of 320 kS/s. Multiple boards can be synchronized using external clock and trigger input options.

The MCC 118 is the first in a series of MCC DAQ HATs. More of DAQ boards are due by the end of the year. The MCC home page mentions a “coming soon” Voltage Output/DIO HAT with two analog output channels and eight digital I/O. Users will be able to mix and match future MCC DAQ HATs with the MCC 118 on a single stack.

The MCC 118 is provided with an external scan clock and an external digital trigger input. The board has a dimension of 65 x 56.5 x 12mm. It has a 0 to 55°C temperature range and is powered at 3.3V from the Raspberry Pi via the GPIO connector.

The MCC 118 comes with an open source, Raspbian-based MCC DAQ HAT Library available for C/C++ and Python. API and hardware documentation is provided with the shipping unit. The user also gets an array of sample programs including a C/C++ based DataLogger and a Python-based web server and IFTTT web service.

The MCC 118 is now available for $99. More information can be found on the MCC 118 announcement and product page.

Installing the Arduino Bootloader on the Atmega328p Microcontroller

Atmega328P

Cost and size, just to mention a few, makes using an Arduino board in certain projects an overkill, often times its always too big, or too expensive for the scope of the project especially when it’s a project that we need to make several units. One good way to retain the simplicity that comes with the use of the Arduino platform while avoiding all other deficiencies is to use the Atmega328p microcontroller alone and program it using the Arduino IDE and its simplified version of the C programming language. However, the atmega328p microcontroller cannot be used with the Arduino IDE until it is flashed with the Arduino bootloader.

Our goal for this tutorial will be to understand how the Arduino bootloader works and how an Atmeg328p microcontroller can be flashed with it.

Installing the Arduino Bootloader on the Atmega328p Microcontroller – [Link]

Flashing Arduino Bootloader on Atmega328p Microcontroller

Introduction

Cost and size, just to mention a few, makes using an Arduino board in certain projects an overkill, often times its always too big, or too expensive for the scope of the project especially when it’s a project that we need to make several units. One good way to retain the simplicity that comes with the use of the Arduino platform while avoiding all other deficiencies is to use the Atmega328p microcontroller alone and program it using the Arduino IDE and its simplified version of the C programming language. However, the atmega328p microcontroller cannot be used with the Arduino IDE until it is flashed with the Arduino bootloader.

Our goal for this tutorial will be to understand how the Arduino bootloader works and how an Atmeg328p microcontroller can be flashed with it.

Atmega328P mcu

The Arduino Bootloader

Programming microcontrollers can be a bit tricky, as they require special programmers and .hex files, not to mention the huge knowledge of the C programming language required to write the code. It’s not beginner friendly, thus to eradicate these issues, Arduino created a .hex file which can be installed on AVR chips that allow you to program the board over a serial port, ensuring all that is needed to program a microcontroller (after installing the hex file) is a serial connection between the microcontroller and the Computer which can be achieved using a USB to UART adapter. This hex file is called the Arduino Bootloader.

The bootloader is very similar to the BIOS Running on a PC and performs two tasks:

  1. It monitors the serial communication line to see if the computer is trying to program it. If this is the case, it accepts the code from the computer and stores it in a specific location in the memory of the microcontroller in such a way that the bootloader itself is not overwritten.
  2. When the computer isn’t trying to upload code to the microcontroller, the bootloader instructs the chip to run the code that’s already stored in memory. Once it locates and runs your program, the Arduino continuously loops through the program and does so as long as the board has power.

Asides from the need to use the Atmega328p in standalone mode, flashing the microcontroller with the bootloader may be necessary when you need to replace the microcontroller on your Uno board for instance or when you need to restore a bricked board which no longer allows code uploads.

Burning the Bootloader to a Microcontroller

There are quite a number of techniques for burning the Arduino bootloader to the microcontroller but we will focus on using the easiest method which involves the use of the Arduino board as an In-System Programmer (ISP).

During the manufacturing process for electronic devices, microcontrollers are usually programmed after they have been mounted on the PCB. This Programming process is referred to as In-System Programming (ISP) and it requires the PCB to have certain header pins through which the microcontroller can be accessed for programming. Most Arduino and Arduino boards also come with this feature as they usually have 2X3 pin headers which are used for a form of In-System programming known as in-circuit serial programming (ICSP). The header pins comprise of 3 SPI pins (MOSI(D11), MISO(D12), SCK(D13)), VCC, GND  and a reset pin and these are the pins used to program the microcontroller on the Arduino. By connecting a Atmeg328p microcontroller to these pins, we will be able to flash the Atmeg328p microcontroller with the Arduino bootloader.

Required Components

The following components are required to follow this tutorial;

  1. Arduino Uno/Duemilanove
  2. Jumper Wires
  3. BreadBoard
  4. Atmega328p microcontroller
  5. 16 MHz crystal oscillator
  6. 22pf capacitors

Bootloader Upload Procedure

1. Prepare the Arduino as an ISP Programmer

Under the examples shipped with the Arduino IDE is the “Arduino as ISP” example which when uploaded to an Arduino board transforms the board into an ISP programmer. Open the example and Upload to your Arduino Uno or Duemilanove.

 

Arduino as ISP Example

2. Wiring 

Next, connect the Atmega328p to be flashed to the Arduino via a breadboard as shown in the Schematics below.

Schematics

Below is a pin map of the connections so it is easier to follow.

Arduino – Atmega328P

D13 - Pin 19
D12 - Pin 18
D11 - Pin 17
D10 - Pin 1 Reset (no Capacitor needed).
VCC - 5V
GND - GND

Some setups include extra parts like LEDs which are used to monitor the bootloading status, but these are not necessary, as long as your connections are correct, burning the bootloader takes only a couple of minutes.

3. Burn the Bootloader

With the connections done, we are now ready to burn the bootloader.

Prepare the Arduino IDE by going to tools, Boards, then select the Arduino Uno as the board type. With that done, go to tools>programmer and select “Arduino as ISP” as the programmer. The final action to burn the bootloader is to go to tools and select Burn Bootloader. It will take the board you selected and search the board.txt file for the bootloader associated to it in the bootloader folder. It is important that your Arduino IDE is properly installed with all the board files as this will not work if the selected board type is not available, but its a very rare scenario.

Select Burn Bootloader

 

With this done, You should now be able to upload any code directly from the Arduino IDE to the Atmega328P microcontroller and use it for standalone purposes.

With the bootloader now on the chip, you can start uploading custom Arduino sketches to it following the tutorial here.

That’s it for this tutorial, Thanks for reading. Feel free to drop any question you might have as regards this via the comment section.

Till next time

muArt – A Simple Serial Adapter Like No Other

UART has become a popular term with microcontroller applications, with the rise of the Arduino, Raspberry Pi, and other open hardware electronics. UART has become a standard for microcontrollers to communicate with each other and exchange data.

A UART can be used not just for data exchange between microcontrollers, single board computers, and other hackers boards, but is also a compelling interface for programming and even debugging devices. A major issue (or maybe minor depending on your use case) while debugging or programming with a USB-to-TTL adapter is the operating voltage, as most adapters usually come with a specific operating voltage and one could potentially damage a target device if the wrong adapter is selected. Also, some converters typically don’t have enough functionality (usually no GPIOs) for most of the use cases. I personally have quite a lot of TTL converters, but a new TTL adapter called the μArt promises to change all that.

μArt

The μArt is a USB to UART-TTL Adapter that aims to solve the issues highlighted above. The μArt is designed to be the only USB to TTL adapter you will ever need, and it is said to be a “truly versatile, safe, and dependable.” The board promises to support several devices whether it is the ESP8266 or some low-power ARM board, regardless of voltage levels, electric potentials, communication speed, or irrespective if it’s used for data exchange, a debugger or a programming tool. It’s still got you covered.

The board is capable of working with a range of voltages levels, from 1.8 to 5.4 V, which should handle most (if not all) voltages for MCU boards and single-board computers. It comes with complementary voltage auto-sensing, meaning you don’t have to worry about selecting the operating voltage yourself, unlike some other boards. It just works. The board also comes with safety features like galvanic isolation and over-current protection, and one header exposing I/Os.

Quality problems are usually also a concern when working on some applications. Some unwanted noise could find its way into a board, due to floating pins, ruining application state, or due to a lousy connection, poor host device, and others. Which if not taken seriously, could potentially damage the device, I have already lost an Arduino board due to a poor host before. Also not let’s forget things like latchups, unexpected freezes (where you could think something is wrong with the code), data errors, and some other possible problems. The μArt USB to TTL adapter is expected to take away all those, giving you a smooth ride while developing your project.

Below are the key features of the device:

  • A Universal TTL-UART –
    • Voltage support: 1.8 – 5.4 V,
    • Speed – up to 3M speed,
    • Baud rates – standard & non-standard baud rates,
    • Handshaking – Available pins for handshaking and flashing various MCU families.
  • Safety features like Galvanic isolation, an integrated pull-up, signal- and power-filters.
  • Reverse-polarity protection, ESD protection, over-current protection, and even mechanical protection
  • Others –
    • Voltage autosensing,
    • LEDs,
    • GPIOs.
  • Dimensions – 58 x 33 x 14 mm.
  • Weight – 16 grams

“The μArt has all the pins and features to enable various applications, protections to withstand or even prevent faults, means to preserve signal integrity, and measures to improve usability. …

The μArt is based on the principle that a UART adapter is your tool, and you should be able to trust your tools to get the job done.

The μArt is currently being crowdfunded on Crowd Supply and has already surpassed its initial goal (of course it would). The board is available from a starting price of $32 for a single device, and up to $112 for a pack of 4 μArts. More information about the product is available on the campaign page.

NanoPi M4 – RK3399 Based RPi Clone SBC Costs $65

FriendlyElec has launched the NanoPi M4. It is one of the smallest, most affordable Rockchip RK3399 based SBC yet. The NanoPi M4 has essentially the same layout as the latest Raspberry Pi 3 Model B+ and has all of its stand out features. Aside from the different processor, this is a very close resemblance of the RPi 3 B+ except for the lack of PoE support on the GbE port.

On the other hand, it has a faster, native GbE port instead of the RPi 3 B+’s USB-based connection. Like the B+, it has dual-channel 802.11ac on the WiFi/Bluetooth module.

Despite the performance improvements on the RPi 3 B+, the Rockchip RK3399 beats it in speed tests. It also defeats the vast majority of Arm SoCs. The RK3399 has dual Cortex-A72 cores clocked to up to 2.0GHz and 4x Cortex-A53 cores at 1.5GHz. There’s also a high-end Mali-T864 GPU and a VPU that supports 4K VP9 and 4K 10-bit H265/H264 60fps decoding.

The NanoPi M4 is intended for applications including machine learning, AI, deep learning, robots, industrial control, industrial cameras, advertisement machines, game machines, and blockchain. OS support for this board includes Android 7.1.2 and three Ubuntu-based Linux distributions: Lubuntu 16.04, FriendlyCore 18.04 (Ubuntu Core), and FriendlyDesktop 18.04.

Specifications for the NanoPi M4:

  • Processor:
    • Rockchip RK3399 (2x Cortex-A72 at up to 2.0GHz,
    • 4x Cortex-A53 @ up to 1.5GHz); Mali-T864 GPU
  • Memory:                                                            
    • 2GB or 4GB LPDDR3 RAM (dual-channel)
    • eMMC socket
    • MicroSD slot for up to 128GB
  • Wireless:
    • 802.11b/g/n/ac (2.4GHz/5GHz) with Bluetooth 4.1;
    • 2x IPX antenna connectors
  • Networking: Gigabit Ethernet port
  • Media:
    • HDMI 2.0a port (with audio and HDCP 1.4/2.2) for up to 4K at 60Hz
    • MIPI-DSI (4-lane) with MIPI-CSI co-lay
    • 1x or 2x 4-lane MIPI-CSI (up to 13MP) with dual ISP support; (2nd CSI available via DSI)
    • 3.5mm analog audio I/O jack
  • Other I/O:
    • 4x USB 3.0 host ports
    • USB 3.0 Type-C port (USB 2.0 OTG or power input)
    • Serial debug 4-pin header
  • Expansion:
    • 40-pin RPi compatible header — 3x 3V/1.8V I2C, 3V UART,
    • 3V SPI, SPDIF_TX, up to 8x 3V GPIOs, 1.8V 8-ch. I2S
  • Power: DC 5V/3A input or USB Type-C
  • Operating temperature: -20 to 70℃
  • Dimensions: 85 x 56mm; 8-layer PCB
  • OS Support: Android 7.1.2; Lubuntu 16.04 (32-bit); FriendlyCore 18.04 (64-bit), FriendlyDesktop 18.04 (64-bit)

The NanoPi M4 with 2GB RAM is available now for $65 (for first 300 units), otherwise, the price is $75. The 4GB version costs $105. More information may be found at FriendlyElec’s NanoPi M4 shopping pagewiki, and GitHub page.

(update 27/06/2019) FriendlyELEC has now decided, certainly in response to Raspberry Pi 4 offering, to lower the price to $50 for the 2GB RAM version which compares to $45 with Raspberry Pi 4 2GB, as well as $75 for the 4GB RAM version (was $95).

Tachyon – 120MHZ 32-bit Arduino Compatible Microcontroller

The Tachyon is a new lightning-fast open-source Arduino Zero-compatible board developed by Rabid Prototypes, currently on Kickstarter for funding. It features a 32-bit ARM M4F processor running at 120MHz and contains 128K of RAM. The Tachyon’s pinout is nearly identical to both the Neutrino and Arduino Zero, making it a go-with replacement for practically any project using either one.

Arduino Zero-compatible Tachyon
Arduino Zero-compatible Tachyon

The Tachyon is an open source board. The users will be provided with the Eagle cad files and schematics with which they’re free to modify and integrate it into their own designs, without ever paying any extra to the real developers.

Programming this board is going to be easy like most Arduinos. A user can simply plug the board into the PC using a micro USB cable and program it with the Arduino IDE as usual. The Tachyon ships with the Zero bootloader installed.

To create the Tachyon it was needed to make only a few minor tweaks to the Neutrino’s layout to get the new chip to work with it. Specifically, the values of two capacitors were changed, and one pin, which the Zero broke out for an RX LED, but which was not broken out on the Neutrino, was re-purposed for the chip’s internal switching regulator.

Most importantly, the SAMD51 is so similar to the SAMD21, most libraries written for the Zero should work on the Tachyon without any modification. So it has the potential to be quite effective and smart Arduino Zero or Neutrino substitute board.

Technical Specs for Tachyon:

  • Microcontroller: Microchip ATSAMD51G18A ARM Cortex M4F @120MHz
  • Operating voltage: 3.3V
  • I/O pin limits: 3.3V, 7 mA
  • Digital I/O pins: 14 w/ 12 PWM
  • Analog input pins: 6 12-bit ADC channels
  • Analog output pins: 2 10-bit DACs
  • Flash memory: 256 KB
  • SRAM: 128 KB
  • Voltage regulator: 3.7-5.5V input / 3.3V, 300mA output
  • Dimensions: 1.4 x 0.7″ (36mm x 18mm)

This board is currently available at Kickstarter. Early shipment to the backers will start from October this year. More information can be found on their Kickstarter page.

Tutorial, Experiment & Teardown of a 24GHz Doppler Radar Module

In this episode Shahriar demonstrates a full analysis of a CDM324 24GHz Doppler radar module from IC Station. Opening the module reveals a series of microwave PCB components and several active devices. A complete analysis of the module is presented. The unit is then measured and the impact of antenna impedance and power supply voltage on the output frequency is measured. The phase noise of the output signal is also measured. Using a series of servo motors, the radiation pattern of the antenna array in both azimuth and elevation is also presented.

Using the radar module the speed of a computer fan is remotely measured using an oscilloscope and FFT function.

Tutorial, Experiment & Teardown of a 24GHz Doppler Radar Module – [Link]

Display kit turns panel PCs into fully featured digital displays

AAEON, a major developer of industrial computing solutions, is releasing a Display Box Kit to work in conjunction with its successful OMNI Series. The new kit builds on the series’ modular design and allows users and distributors to quickly convert panel PCs into digital displays and vice-versa. In addition to connecting Display Box Kits to existing Panel Kits, customers can also buy complete OMNI Display units.

The OMNI Display Series includes panels in seven different sizes, ranging from 10.4” to 21.5”. They are all fitted with Full HD LCD displays and customers can choose between PCAP and resistive touchscreen models. Stylish and robust, the panels are finished with an IP65 aluminum front bezel and feature a variety of power protections. They offer a 12V~30V DC power input range, OVP, UVP, OCP, and reverse power protection, and customers can also choose between terminal block and power jack connections. The panels’ rugged versatility is increased by their -10 oC~55 oC operating temperature range.

AAEON’s commitment to user-friendly design means the new Display Box Kit only takes minutes to install, as just three screws are used to fasten the kit – and the alternative CPU Box Kit – to the display panel. The new product gives users access to both VGA and HDMI video interfaces, and a USB port enables connection to a PC, and built in speakers are available as an option.

“By developing a product series with interchangeable modules, AAEON is working to streamline the manufacturing and distribution process and make it easier for customers to get the equipment they need, when they need it,” said AAEON system platform division product manager Raven Hsu.

AAEON – www.aaeon.com

Smart fan with face detection camera

Smartphone’s camera detects your face and the fan moves automatically according to your face. This is an easy project using obniz, servo motor, smartphone, and a fan.

Required Components

  • Obniz
  • Servo motor
  • Small USB fan
  • USB <-> Pin header
  • Pin header
  • Cable
  • USB-Cable
  • USB-Adaptor

How it works

We use HTML5 Multimedia to use smartphone’s camera.

Step 1 – setting up obniz

To get started, all you need to do is to follow three steps.

1.    Connect obniz to wifi

2.    Connect devices like LED or motors to obniz

3.    Scan QR code of obniz and start programming. You do not need to install any software.

 

https://youtu.be/3GYG8BjfcXg

Step 2 – Hardware

We need to follow three steps for the hardware.

  1. Connect obniz and a servo motor
  2. Connect Small USB Fan to USB <-> Pin header, and connect it to obniz.
  3. Connect obniz to Power supply.

Step 3 – software

1. With HTML5 Multimedia, we can get camera data

We use navigator.getUserMedia(). The browser asks user to permit.
Then, callback parameter stream are set to video tag, and display camera pic on html

It is only HTTPS protocol.

<video id="videoInput" autoplay playsinline width=320 height=240>
<button id="startAndStop">Start</button>

<script>
  let videoInput = document.getElementById('videoInput');
  let startAndStop = document.getElementById('startAndStop');

  startAndStop.addEventListener('click', () => {
    if (!streaming) {

      navigator.mediaDevices = navigator.mediaDevices || ((navigator.mozGetUserMedia || navigator.webkitGetUserMedia) ? {
        getUserMedia: function (c) {
          return new Promise(function (y, n) {
            (navigator.mozGetUserMedia ||
                navigator.webkitGetUserMedia).call(navigator, c, y, n);
          });
        }
      } : null);

      if (!navigator.mediaDevices) {
        console.log("getUserMedia() not supported.");
        return;
      }

      const medias = {
        audio: false,
        video: {
          facingMode: "user"
        }
      };

      navigator.mediaDevices.getUserMedia(medias)
          .then(function (stream) {
            streaming = true;
            var video = document.getElementById("videoInput");
            video.src = window.URL.createObjectURL(stream);
            video.onloadedmetadata = function (e) {
              video.play();
              onVideoStarted();
            };
          })
          .catch(function (err) {
            console.error('mediaDevice.getUserMedia() error:' + (error.message || error));
          });

    } else {
      utils.stopCamera();
      onVideoStopped();
    }
  });

  function onVideoStarted() {
    startAndStop.innerText = 'Stop';

   // ...
  }

  function onVideoStopped() {
    startAndStop.innerText = 'Start';

   // ...
  }

</script>

2. Face detect with camera data and OpenCV

We use OpenCV Sample.
haarcascade_frontalface_default.xml is face data, and we use it for detect face.

<canvas id="canvasOutput" width=320 height=240 style="-webkit-font-smoothing:none">

<script src="https://docs.opencv.org/3.4/opencv.js"></script>
<script src="https://webrtc.github.io/adapter/adapter-5.0.4.js" type="text/javascript"></script>
<script src="https://docs.opencv.org/3.4/utils.js" type="text/javascript"></script>

<script>

let streaming = false;

function onVideoStopped() {
streaming = false;
canvasContext.clearRect(0, 0, canvasOutput.width, canvasOutput.height);
startAndStop.innerText = 'Start';
}

let utils = new Utils('errorMessage');

let faceCascadeFile = 'haarcascade_frontalface_default.xml';
utils.createFileFromUrl(faceCascadeFile, 'https://raw.githubusercontent.com/opencv/opencv/master/data/haarcascades/haarcascade_frontalface_default.xml', () => {
startAndStop.removeAttribute('disabled');
});

async function start() {
let video = document.getElementById('videoInput');
let src = new cv.Mat(video.height, video.width, cv.CV_8UC4);
let dst = new cv.Mat(video.height, video.width, cv.CV_8UC4);
let gray = new cv.Mat();
let cap = new cv.VideoCapture(video);
let faces = new cv.RectVector();
let classifier = new cv.CascadeClassifier();


let result = classifier.load("haarcascade_frontalface_default.xml");

const FPS = 30;

function processVideo() {
try {
if (!streaming) {
// clean and stop.
src.delete();
dst.delete();
gray.delete();
faces.delete();
classifier.delete();
return;
}
let begin = Date.now();
// start processing.
cap.read(src);
src.copyTo(dst);
cv.cvtColor(dst, gray, cv.COLOR_RGBA2GRAY, 0);
// detect faces.
classifier.detectMultiScale(gray, faces, 1.1, 3, 0);
// draw faces.
for (let i = 0; i < faces.size(); ++i) {
let face = faces.get(i);
let point1 = new cv.Point(face.x, face.y);
let point2 = new cv.Point(face.x + face.width, face.y + face.height);
cv.rectangle(dst, point1, point2, [255, 0, 0, 255]);
}
cv.imshow('canvasOutput', dst);

// schedule the next one.
let delay = 1000 / FPS - (Date.now() - begin);
setTimeout(processVideo, delay);
} catch (err) {
console.error(err);
}
};

// schedule the first one.
setTimeout(processVideo, 0);

}

</script>

 

3. Detect x position of your face and rotate the servo motor

The code is not complicated.
Only we need is where we wired obniz to servo motor and USB, and how to rotate the servo motor.

new Obniz(“OBNIZ_ID_HERE”); is the code of connection to obniz

<script src="https://unpkg.com/[email protected]/obniz.js"></script>

<script>
let obniz = new Obniz("OBNIZ_ID_HERE");
let servo;
obniz.onconnect = async () => {
obniz.display.print("ready")
var usb = obniz.wired("USB" , {gnd:11, vcc:8} );
usb.on();

servo = obniz.wired("ServoMotor", {signal:0,vcc:1, gnd:2});

}

if(/* when detect face */){
servo.angle(xPos * 180 / 320);
}

</script>

 

What is Obniz?

obniz is a cloud-connected IoT development board. You can program on the web browser of any smartphone or computer and the command is sent to obniz through the internet via obniz cloud. By connecting the obniz to the cloud through wifi, users can remotely control devices that are physically connected to obniz.

obniz has 12 IO and WiFi-BLE module. It can be controlled through the APIs – REST or WebSocket API – on obniz cloud. Not only simple IO on/off but also UART, I2C, BLE etc can be used by remotely controlling obniz via internet. All you need to do to connect obniz is to input unique ID by scanning QR code. Complicated processes are done by obniz and its cloud. You can just start programming in HTML, browser and circuit have already been integrated. If you write a program to collect sensor values, you can make a chart of the values easily.

In terms of hardware, every IO can drive up to 1A with overcurrect protection, therefore high current demanding devices such as motors can be directly connected to obniz IO. GPIO and AD can be used on every IO. UART, SPI etc peripherals can be assigned to every IO. Even output voltage 3v/5v can be changed by software. Most electrical parts can be connected directly. Embedded parts such as switch, OLED display, and BLE are ready for use on program.

More information on obniz is available on its website

Program

<!-- HTML Example -->

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Video Capture Example</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<script src="https://docs.opencv.org/3.4/opencv.js"></script>
<script src="https://obniz.io/js/jquery-3.2.1.min.js"></script>
<script src="https://unpkg.com/[email protected]/obniz.js"></script>
<style>
.refrect-lr {
-webkit-transform: scaleX(-1);
-o-transform: scaleX(-1);
-moz-transform: scaleX(-1);
transform: scaleX(-1);
filter: FlipH;
-ms-filter: "FlipH";
}
</style>
</head>
<body>

<div id="obniz-debug"></div>

<div>
<div class="control">
<button id="startAndStop">Start</button>
</div>
</div>
<p class="err" id="errorMessage"></p>
<div>
<table cellpadding="0" cellspacing="0" width="0" border="0">
<tr>
<td>
<video id="videoInput" autoplay playsinline width=320 height=240 class="refrect-lr"></video>
</td>
<td>
<canvas id="canvasOutput" width=320 height=240 style="-webkit-font-smoothing:none"

class="refrect-lr"></canvas>
</td>
<td></td>
<td></td>
</tr>
<tr>
<td>
<div class="caption">videoInput</div>
</td>
<td>
<div class="caption">canvasOutput</div>
</td>
<td></td>
<td></td>
</tr>
</table>
</div>

<script src="https://webrtc.github.io/adapter/adapter-5.0.4.js" type="text/javascript"></script>
<script src="https://docs.opencv.org/3.4/utils.js" type="text/javascript"></script>
<script type="text/javascript">

let servo;


obniz = new Obniz("OBNIZ_ID_HERE");

obniz.onconnect = async () => {
obniz.display.print("ready")

let usb = obniz.wired("USB", {gnd: 11, vcc: 8});
usb.on();

servo = obniz.wired("ServoMotor", {signal: 0, vcc: 1, gnd: 2});

}

let utils = new Utils('errorMessage');

let faceCascadeFile = 'haarcascade_frontalface_default.xml';
utils.createFileFromUrl(faceCascadeFile, 'https://raw.githubusercontent.com/opencv/opencv/master/data/haarcascades/haarcascade_frontalface_default.xml', () => {
startAndStop.removeAttribute('disabled');
});


let streaming = false;
let videoInput = document.getElementById('videoInput');
let startAndStop = document.getElementById('startAndStop');
let canvasOutput = document.getElementById('canvasOutput');
let canvasContext = canvasOutput.getContext('2d');


startAndStop.addEventListener('click', () => {

if (!streaming) {
utils.clearError();


navigator.mediaDevices = navigator.mediaDevices || ((navigator.mozGetUserMedia || navigator.webkitGetUserMedia) ? {
getUserMedia: function (c) {
return new Promise(function (y, n) {
(navigator.mozGetUserMedia ||
navigator.webkitGetUserMedia).call(navigator, c, y, n);
});
}
} : null);

if (!navigator.mediaDevices) {
console.log("getUserMedia() not supported.");
return;
}

const medias = {
audio: false,
video: {
facingMode: "user"
}
};

navigator.mediaDevices.getUserMedia(medias)
.then(function (stream) {
streaming = true;
var video = document.getElementById("videoInput");
video.src = window.URL.createObjectURL(stream);
video.onloadedmetadata = function (e) {
video.play();
onVideoStarted();
};
})
.catch(function (err) {
console.error('mediaDevice.getUserMedia() error:' + (error.message || error));
});


} else {
utils.stopCamera();
onVideoStopped();
}

});

function onVideoStarted() {
startAndStop.innerText = 'Stop';
start();
}
function onVideoStopped() {
streaming = false;
canvasContext.clearRect(0, 0, canvasOutput.width, canvasOutput.height);
startAndStop.innerText = 'Start';
}

async function start() {
let video = document.getElementById('videoInput');
let src = new cv.Mat(video.height, video.width, cv.CV_8UC4);
let dst = new cv.Mat(video.height, video.width, cv.CV_8UC4);
let gray = new cv.Mat();
let cap = new cv.VideoCapture(video);
let faces = new cv.RectVector();
let classifier = new cv.CascadeClassifier();


let result = classifier.load("haarcascade_frontalface_default.xml");

const FPS = 30;

function processVideo() {
try {
if (!streaming) {
// clean and stop.
src.delete();
dst.delete();
gray.delete();
faces.delete();
classifier.delete();
return;
}
let begin = Date.now();
// start processing.
cap.read(src);
src.copyTo(dst);
cv.cvtColor(dst, gray, cv.COLOR_RGBA2GRAY, 0);
// detect faces.
classifier.detectMultiScale(gray, faces, 1.1, 3, 0);
// draw faces.
for (let i = 0; i < faces.size(); ++i) {
let face = faces.get(i);
let point1 = new cv.Point(face.x, face.y);
let point2 = new cv.Point(face.x + face.width, face.y + face.height);
cv.rectangle(dst, point1, point2, [255, 0, 0, 255]);
}
cv.imshow('canvasOutput', dst);
if (servo && faces.size() > 0) {
let face = faces.get(0);
servo.angle((320 - (face.x + face.width / 2)) * 180 / 320);
}

// schedule the next one.
let delay = 1000 / FPS - (Date.now() - begin);
setTimeout(processVideo, delay);
} catch (err) {
console.error(err);
}
};

// schedule the first one.
setTimeout(processVideo, 0);

}
</script>
</body>
</html>

The Fishino Piranha – A Development Board With 120MHz 32bit Microcontroller

A few weeks ago Open Electronics announced their new “Fishino Piranha” board. It is one of the first boards to imitate the Arduino MKR. The Fishino Piranha follows with the release of their Uno-inspired “Fishino 32” board, which was released at the start of last year.

The Piranha has the same 32-bit Microchip PIC32MX as the previous board with a MIPS core clocked at 120MHz. It comes with 128 kB RAM and 512 kB Flash memory and has the same form factor as the new Arduino MKR boards. The layout of the Piranha’s headers is more or less identical to that of MKR1000. Only with the exception of the analog output (DAC). There is no DAC present on the PIC32MX processor used here in this board.

The Fishino Piranha
The Fishino Piranha Development Board

The Piranha also has native USB support, both host and client, an RTC, MicroSD card slot, and Wi-Fi onboard provided using an ESP8266 module. The board is designed to be powered from the micro-USB socket, or through the external power source. Otherwise with a battery charger, based on the Microchip MCP73831, for the LiPo built-in. While the board uses 3.3V internal logic, the pins are tolerant up to 5V. Thus considering no risk of damaging the board with 5V peripherals.

The board is fully Arduino-compatible and can be developed either using the FishIDE, which Open Electronics has created as an alternative to the traditional Arduino IDE, or directly from the Arduino development environment as usual.

Highlighted features of the Fishino Piranha:

  • High-performance PIC32MX controller
  • high performance, with 120 MHz clocks, 512 KBytes flash and 128 KBytes RAM
  • WiFi module on board
  • MicroSD card reader on board
  • RTC module on board
  • High performance switching power supply
  • Can be powered by a single cell LiPo battery, with onboard charger
  • Can be powered off by software and awaken by external events
  • Pinout and size compatible with Arduino MKR1000

The Fishino Piranha board is available now at around $42 from the Open Electronics store. More details of the board design can be found in their announcement page.

TOP PCB Companies