Friday, 21 August 2015

A 128x64 GLCD for Teensy 3.x

The aim of this project is to use a high-speed port to transfer eight bits at a time on a graphical display 128x64. To do this I have studied a suitable configuration of Teensy I/O and  also have modified the KS0108 library, as described in my post "Teensy rev.3.1 and KS0108 Graphic LCD library".
This system can be used in several applications, such as portable low frequency oscilloscopes, FFT analyzers, data loggers etc.
The complete diagram of my project is visible in the figure below.

Warning: As can be seen from the circuit diagram, I connected directly the LCD display to the Teensy pins. This is because the Teensy 3.1 and 3.2 cards are 5 volts tolerant. Do not use a Teensy 3.0 or LC or other boards with processors that don’t tolerate 5 volts TTL signals. In this case a bi-directional voltage level adapter must be used for the display 8 bits data bus.

I also add an SD board module, a J3 connector for the serial interface, a J4 connector with the rest of the bits of I/O available and a battery for Teensy RTC.
For the power supply I used a power bank, as I wrote in the post "A very simple way to power Arduino".
As illustrated in the scheme, I used a special display with RGB backlight (Winstar WG12864A Rev.J), which has 22 pins instead of 20. You can use a more common  display based on NT7108 controller or equivalent.
In the tables below you can see the pin layout of the display used in this project and the connections with the Teensy board.
The figure below shows the breadboard with the components used, the LCD display, Teensy and the SD module are not yet mounted.
The lithium battery is used for the Real Time Clock Teensy, on which I welded the small quartz with a frequency of 32768 Hz.
In Google Drive (  I created the folder ‘Teensy’ where I put the file with the library modified and, in the examples, I added my small test program TeensyGLCD.ino. I recognize that my changes are not very elegant as programming style but work well and reach the goal. Suggestions and modifications by users are well accepted.
With few changes I also ran on my Teensy GLCD, the program arduino-oscillo.pde of Noriaki Mitsunaga (3), an interesting oscilloscope which uses the same library and display.
1) “Tutorial on digital I/O, ATMega PIN/PORT/DDR D/B registers vs. ARM GPIO_PDIR / _PDOR” - immortalSpirit - Jan 2013.
2) “K20 Sub-Family Reference Manual”- Freescale - Document Number: K20P64M72SF1RM, Rev. 1.1, Dec 2012.
3) “Arduino Oscilloscope”, Noriaki Mitsunaga,

Monday, 17 August 2015

4-20 mA current output for Arduino Due

Arduino Due does not have an analog output voltage from 0 V to Vref, but from 1/6 to 5/6 of the reference voltage, corresponding to voltage values of 0.55 V and 2.75V with a typical Vref = 3.3 V. This is also confirmed by the Atmel (see bibliography 1).
I do not know if it is wanted by the ARM Cortex-M3 CPU designers, but the ratio between the maximum value and the minimum of the output voltages of Arduino Due is exactly five, such as that between 20 and 4 mA, the standard used for the transmission of analog measurements in the industrial plants.

This has facilitated the design of an electronic circuit in order to obtain at the output a current range of 4 to 20 mA. The following diagram shows this simple circuit. It uses a single-rail LM358 operational amplifier and an NPN darlington transistor and a few other components.
The operational amplifier U1 and the transistor Q1 realize a tracking system, so that the voltage on emitter resistor R2 is equal to the input voltage.  Keeping constant the voltage on a resistor, by the Ohm's law, means that even the current is constant. In this way, the transistor emitter current Ie, flowing in R2, is dependent on the input voltage, therefore the circuit behaves as a current generator controlled by the input voltage.
From Kirchhoff's Current Law the collector current is: Ic = Ie – Ib, where Ib is the base current of transistor: Ib = Ic /hfe and hfe is the common-emitter current gain. Using a transistor with a hfe> 100 or greater, we can neglect the base current of the transistor and assert that also the collector current remains constant and proportional to the input voltage. A darlington transistor has an even greater current gain, so that we can assume that Ic = Ie.
The trimmer pot is used to adjust the maximum output current (20 mA) at the maximum number (4095) of the DAC or the maximum output voltage. This value, in the typical case of 3.3*5/6 is equal to 2.75 V, for which:
R2 = 2.75V /20mA = 137.5 Ω
In practice there may be slightly different values, therefore, it's better to use a potentiometer to precisely calibrate the current.
Powering the circuit with 5 V, supplied by of Arduino, the load can’t have higher voltages of 1 volt. Indeed, at 20 mA the voltage on R2 will be equal to about 2.75 V, which must be added to the Vce of the transistor which must not saturate. During the tests I used a digital ammeter that require a maximum of 0.2V on its terminals. For these reasons it is better to use higher supply voltages as 12 V or, better, 24 V. By varying the supply voltage does not involve variations of the circuit, but only an increase of dissipation on the transistor. In these cases a darlington medium power transistor is a good choice, as a TIP110, BD675, or similar.
 Don’t use operational amplifier as LM741, LM1458, TL081 and other that are not suitable for single-supply.
The photo below show the circuit, built on a bread board, during the test. For the interface with my Arduino Due system, I used a DB25 connector, mounted under the card.
To test the circuit, I wrote a simple program that sends to the DAC0  of Arduino Due, values of N according to the table: {0,512,1024,2048,3072,3584,4095}. They are generated in succession, each time I press the a button connected to pin 32. In the picture below you can see the circuit connected to my system, based on an Arduino Due and a LCD display. 
For the calibration measurements I used both a digital DMM, as shown in the photo, and a more accurate high resolution voltmeter on a precision 200.0 Ohm resistor, acting as load.
The results of these measurements were very good, as is also clear from the trend curve shown in the following figure and from R2, almost equal to one.
1)      “Atmel ARM Cortex-M3 Product Family (SAM3)”, Atmel application note 42187A−SAM−10/2013

Thursday, 13 August 2015

A very simple way to power Arduino

A simple and inexpensive solution is to use a 'mobile power bank', which is now widely available at low cost (from 5 €). The capacity of these systems is very high, almost always greater than 2000mAh, although some Chinese manufacturers print values ​​little true, as is the case for the batteries.
It is used to give energy to our smartphone or tablet, in cases in which our cellular battery is discharged or we can’t use the electricity grid. These devices incorporate, in a small volume, one or more rechargeable polymer battery, a charger (5V to 4.2V) and a step-up switching power supply to generate the 5V output from 3.6 V battery.
Normally it has two USB connectors female: output type A to power the phone or tablet and a micro USB for charging the internal battery, it connects to a normal power supply 5-5,5V 1 or 2 A, which is now a standard for the last generation mobile phones o tablets.
Usually they are provided of one or more cables to adapt to phones and tablet, typically with the micro USB or with standard iPhone connector. With the cable terminated with USB Micro, we can supply different cards, including Arduino Due, Yun, Nano and Teensy.
To power Arduino Uno we need a common USB cable A / B USB, like that used for printers.
This type of power supply is particularly suitable for portable and very compact systems, and it has an operating time of several hours. I use these devices for some years.

The photo below shows an example of an application with Arduino Yun.
With the experience of a few years of use of the power banks, may I suggest that you preferably use those that have a power switch. They cost more but do not have an internal consumption that significantly reduces battery life. In some cases I measured a battery discharge current of about 2 mA without any external load.