Tag Archives: GPIO

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.

An introduction to GPIO Settings

Working with microcontrollers means managing GPIO pins at some point. Many configurations have been developed for modern microcontrollers which can lead to some “fancy” terms that may confuse programmers. Its important to understand all of this to avoid confusion and errors while programming.

First, some terms need to be understood. GPIO pins have tri-state logic which means that contrary to popular beliefs GPIO pins can assume 3 states instead of 2. These values are: 0, 1 and high impedance or “Hi-Z”. There is also a state called floating which is when the state is indeterminate and floats between two states. As a result, the pull up and pull down were created, the pull up are resistors that connect a signal to VCC when the signal is floating, and pull downs do the same, but connect the signal to ground. Also, there is a “current sink” which is when the current is flowing into a pin, node, or signal. Conversely, there is a “current source” which is when the current is flowing out of a pin, node, or signal.

The modes of a GPIO pin can be classified into two categories: input, and output. Input mode means that the pin is used to read the state of the electrical signal, they are configured as high-impedance, pull up or pull down. Output modes are used to write a signal as high or low using push-pull or open drain. Push- pull is the default setting in most cases and it works by sourcing or sinking the current. On the other hand, Open- Drain only sinks current which basically makes it a switch with 2 states ground or disconnected. A useful application is for having multiple external devices drive a single, active low interrupt pin.

Regarding functionality, speed is a very important and desired characteristic for GPIO pins since it controls the rate at which it changes state. Speed configurations are referred as “slew rates”, “frequency”, and “high frequency mode”. Increasing speed leads to higher power consumption and a noisier device, so people tend to keep it low unless the project specifically requires more speed.

Another term is “High Drive” GPIO which are push-pull pins that provide more current that usual. These characteristics depend on the device and its recommended to check the datasheet, for example: if a typical GPIO can source/sink 8 mA a high drive device can source/sink 40 mA.

By reading this its easy to notice that the definitions are mostly things we are familiar with, and the only novelty are the terms used to describe them.  Learning and understanding all the modes, functionalities etc. will make working with GPIOs easier and could avoid any issues. You can learn more about GPIO states on the source below.

[source]

BML GPIO-14 USB Board for PCs

BML project for using a $2 FTDI FT260Q for adding 14 bits of GPIO to any PC via USB with no device drivers required.

Ever miss the simple days of using a PC’s LPT1 parallel port to bit-bang GPIO over 8 output pins and 4 input pins of the DB-25 connector? I sure do. My first design project as a BSEE graduate in 1993 was to design a LPT1 controlled test fixture for the Motorola MDT-9100-T data terminal (shown below). Those were the days. By multiplexing 12 parallel port pins into 74HC dip CMOS latches and transceivers my test jig tested all the IO signals of the MDT-9100s 386sx motherboard. All of the diagnostic software could be written in C on my Windows 3.1 desktop thanx to this versatile interface. Those were the glorious simple days of computing. Sigh…. Then USB came along and killed the wonderfully easy parallel port interface.

BML GPIO-14 USB Board for PCs – [Link]

Three Ways to Make Arduino Works As A USB/TTL Converter

Even if you have years working with electronics, you will still find some simple hacks that you never thought about before. Personally and to save money, when I was a student with a very limited budget I knew that my Arduino UNO can work as a USB/TTL(serial) converter. I used to remove the Atmega328P from my Arduino UNO R3 board in order to use the board as a converter not as a development board.

Why we need to do some tweaking to Arduino in order to use 0 and 1 pins for direct USB <-> UART conversion? This is because of what’s called fan-out (fan-out of a logic gate output is the number of gate inputs it can drive). In Arduino UNO case, the RX & TX lines (pins 0 and 1) are connected to FT232RL/Atmega8U2 USB to TTL bridge and to the Atmega328P MCU (check the schematic). So using the same pins with an external connections without doing any changes to Arduino UNO board probably won’t work.

Patel Darshil over Hackster.io listed three ways to make Arduino works as a USB/TTL converter:

Hack #1: Set Pin 0&1 Mode to Input Mode

This is done using code:

Pin Mode Set Arduino

But why this solves the problem? Well, GPIO can operate in two modes, input and output. In the input mode the equivalent impedance of the pin is too high; therefore, the Arduino/Atmega328P’s pins will have almost no electrical effect to the converter RX/TX pins.

Hack #2: Keep Atmega in Reset Mode

Just connect the RES pin with GND (the bold red wire in the image bellow)

Arduino Reset
Image Courtesy of Patel Darshil

GPIOs are configured using special registers. For example, Atmega has GPIO port data direction register (DDR) to set the GPIO as an input or an output for each port. The value of this register is cleared during reset. Therefore, the MCU’s GPIOs mode will be input. This means high impedance, subsequently.

Hack #3: Remove The MCU

This is the common way used by most Arduino UNO users, but it’s not applicable when it comes to new versions of Arduino; where, the MCU is SMD and can’t be removed.

Robust C Library and Utility for GPIO sysfs Interface in Linux

by Derek Hildreth – Technologic Systems

This comprehensive and easy to read example C code is designed to work alone or included as a library for dealing with general purpose I/O via the sysfs interface in Linux.  It can easily be applied to any computer which utilizes the GPIO sysfs interface (both pro and maker boards).  Getting started is a breeze.  You just need to decide if you’re going to use it as a library (including it into your existing code) or as a stand-alone utility.  We’ll talk about  in this article, but first and foremost, here’s the source code we’ll be working with:

https://github.com/embeddedarm/gpio-sysfs-demo

To get started, download or clone this repository to your board, extract it, and change your directory to it, like so:

wget https://github.com/embeddedarm/gpio-sysfs-demo/archive/master.zip
unzip master.zip
cd gpio-sysfs-demo-master/

The two important files in this repository came from Technologic System’s GitHub pages:

The included Makefile makes quick work out of compiling the example code mentioned in the sections below, as you’ll see soon enough.

Stand-Alone Utility

As a stand-alone utility, you can easily copy the resulting gpioctl program to a directory in your current PATH and include in a script or use it for those one-off commands.

To do this, we’ll simply run sudo make install.  The Makefile will compile the standalone utility using (essentially) gcc -D CTL gpiolib.c -o gpioctl and then automatically copy it to /usr/local/bin, which is popularly included in PATH.  Then, you can run gpioctl –help for instructions on how to use it.  For example, say you want to output logical high on DIO #59.  You would first set the DIO to be an output, and then you’d set it.  Here’s an example of toggling it:

gpioctl –ddrout 59

gpioctl –setout 59

gpioctl –clrout 59

That’s it!  If, say, DIO #59 was tied to an LED, you should see the LED turn on and off again.

 

Now you can easily include these commands into a bash shell script or Python system call or, well, you get the point.

Pro Tip: Keep in mind, the LED may be active low, so you might actually see the opposite (logic high output turns the LED off, logic low output turns the LED on).

Include as Library

Okay, so if you wanted to use this as a library, giving our own C program access to the helpful functions included in gpioctl.c, we need to include it as a source when compiling our program.  You’ll find the example source code gpiodemo.c included in the repository you downloaded earlier:

#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include "gpiolib.h"

int main(int argc, char **argv)  {
    int gpio_pin = 59;
    gpio_export(gpio_pin);
    gpio_direction(gpio_pin, 1);

    for(int i = 0; i < 5; i++) {
        printf(">> GPIO %d ON\n", gpio_pin);
        gpio_write(gpio_pin, 1);

        sleep(1);

        printf(">> GPIO %d OFF\n", gpio_pin);
        gpio_write(gpio_pin, 0);   

        sleep(1);
    }                                                                                                                                                      
    return 0;
}

If you simply run make, you’ll get a compiled gpiodemo binary which simply toggles DIO #59, which is connected to an LED on a breadboard.  Referring to the Makefile, you’ll see it’s compiling the example code by running gcc -o gpiodemo gpiolib.c gpiodemo.c.  Now, you can take this knowledge and example and apply it to your own project.

Bonus: Very Fast GPIO

The sysfs API allows for very simple IO access, but it is not very fast.  For example, on the TS-4900 sending out a square wave on a single CPU GPIO through the sysfs API will toggle at around 160 – 170 KHz.  The same IO accessed through registers will toggle at 1.66 – 1.74 MHz.  FPGA GPIO will always be slow at around 700hz.  If you’re needing higher performance GPIO programming in order to meet very specific timing requirements, you might want to take a look at the gpiolib-fast.c solution.  Basically, instead of going through sysfs, you’ll be using the GPIO memory registers directly.  Take care in doing so, as the operations aren’t atomic and can therefore foul things up in unexpected ways.  Kernel drivers or other processes accessing GPIO in the same bank performing a read/modify/write can rewrite the same register with old values causing unexpected results.  Source code can be found here:

Conclusion

You should now be able to control GPIO through the sysfs interface like a boss!  We hope this article was helpful in getting your project off the ground quickly.  If it made your day, please consider sharing it!  If you have questions, please use the comments below.

Low-Cost FPGA With Reconfigurable Electronics Feature

Iolinker is a cheap 64 FPGA board with a MachXO FPGA that functions as a dynamically configurable IO matrix. Its main functionality, besides IO extension, is to dynamically set up a matrix of GPIO connections, that allow direct pass-through of high-frequency signals. Circuits can thereby be configured and programmed on the fly. There are UART / SPI / I2C connections that allow for easy integration of up to 127 chips connected in parallel.

Thanks to the open source library, Iolinker allows developers to create reconfigurable, easy to self test electronics within minutes. It can be used to be an IO extender and can output PWM signals. In addition, its revolutionary “IO linking” feature allows to dynamically pass through high-speed signals between IOs, better than any microprocessor ever could.

Check this teaser about the new board:

Iolinker has the following specifications:

  • Reprogrammable FPGA board with Lattice LCMXO3L-4300E-5UWG81CTR50
  • Preprogrammed and usable out of the box as your IO interface of choice.
  • 49 GPIOs for PWM or IO extension usage, VCCIO is 3.3V.
  • Boards can be connected in parallel, to create endless IO extension.
  • IOs can be linked to each other, i.e. you tell the FPGA to connect them, and it forwards the input signal from one pin to another. (Read more about the iolinker chip function.)
  • UART, SPI or I2C interfaces are available.

In order to make the ultimate IO interface for users, the team are accepting feature requests at the contact page.

In short, the Iolinker board is easy to use and can reconfigure schematics on the fly, what makes it ideal to reduce prototyping time and jumper cable mess, and to maximize the ability of using IO extensions.

More technical details about Iolinker and its price will be announced soon at the Kickstarter campaign at Feb 14. Some special offers are for everyone who register in the website’s newsletter, so register now and stay tuned!

 

ESP8266 controlled with Android app (MIT App Inventor)

featured-image-600x337

Rui Santos from Random Nerd Tutorials tipped us with his latest tutorial on how to build an Android app using the MIT App Inventor software that allows you to control the ESP8266 GPIOs:

ESP8266 controlled with Android app (MIT App Inventor) – [Link]

How to Control ESP8266 GPIO using Android App

This video will guide you to control gpio of esp8266 from android app in details. so that you can build your first home automation project easily.

How to Control ESP8266 GPIO using Android App – [Link]