A simple oscilloscope using Adafruit 2.8" TFT with touch. Runs on FRDM-KL25Z, FRDM-K22F, FRDM-K64F, NUCLEO-F411RE. 2 channel analog inputs with 4 trigger modes and time division.

Dependencies:   SPI_STMPE610 UniGraphic mbed vt100

My first attempt of implementing an oscilloscope using FRDM-KL25Z and Adafruit 2.8" TFT with touch.

FRDM-KL25Z と Adafruit 2.8" TFT with touch を使用して作ってみた最初のオシロスコープです。

On 25-Sep-2017, wrong calculation of trigger pos/val fixed.
On 25-Nov-2015, FRDM-K64F and NUCLEO-F411RE platforms were added.
On 26-Nov-2015, FRDM-K22F is added (tested).
Note: Now ch2 is A2 instead of A1!

25-Sep-2017, トリガー値と位置の計算の誤りを修正しました。
25-Nov-2015, FRDM-K64F と NUCLEO-F411RE でも動くようになりました。
26-Nov-2015, FRDM-K22F でも動作確認が出来ました。 ※一身上の都合で、アナログ入力の ch2 は A1 から A2 に変更しましたので、ご注意ください。m(_ _)m

/media/uploads/Rhyme/oscillo_top.jpg

This supports two analog inputs A0 for channel 1 and A2 for channel 2
and four trigger modes (NONE, RISE, FALL, LEVEL),
time division is 30us to 20ms per pixel which will make 300us/div to 200.0ms/div (as 10 pixels per div)

A0と A2 のアナログ2入力にて、
4種類のトリガーモード(NONE: フリーラン RISE: 立ち上がりエッジ、FALL: 立下りエッジ、LEVEL: レベル) 。
サンプリングは30us から 20ms, チャートの1メモリが10ピクセルなので、300us/dev から 200.0ms/div となっています。

The analog signals and gnd was picked at the pins in the picture above.
Note: now you need to pick A0 and A2 instead of A0 and A1.

信号は上記の写真のように、Adafruit のピンからつまみました。
変更により、A0とA2が入力となります。

/media/uploads/Rhyme/freerunmode.jpg

When powered on or reset, the program starts in Trigger Mode = NONE (Free Run Mode)

電源投入、リセット後 プログラムはトリガーモード NONE (フリーランモード) で起動します。

To change trigger mode and/or time division, press run/stop button.

トリガーモードを変えたり、サンプリング時間を変えるのには run/stop ボタンを押してください。

Each time you push Trig button, the trigger mode changes
NONE -> RISE -> FALL -> LEVEL ( -> NONE).

トリガーボタンを押すたびにトリガーモードは
NONE(フリーラン) -> RISE (立ち上がりエッジ) -> FALL (立下りエッジ) -> LEVEL (レベル)
と変化します。

When trigger mode is not NONE,
to specify the trigger position, level and channel, push inside the wave frame.
Then green trigger marks will be shown and value of trigger position and voltage will be printed.

トリガーモードが NONE でないときに、チャネルの枠内をタッチしますと、
その位置がトリガーのポジション、レベル、チャネルになります。 そして、緑色のトリガーマークが表示され、下部にはトリガーの具体的なポジションとボルテージが表示されます。

/media/uploads/Rhyme/usage_screen1.jpg

To change time division push "1/2" to Zoom Out (sampling interval will be bigger) or
"x2" to Zoom In (Sampling interval will be smaller).

サンプリングタイムを変更するのには
"1/2" ズームアウト (サンプリング間隔が長くなります) か
"x2" ズームイン (サンプリング間隔が短くなります。) を押してください。

/media/uploads/Rhyme/helps.jpg

On 7-Mar-2015 updated to UniGraphic library version!

2015年3月7日 UniGraphic ライブラリ使用版にアップデートしました。

/media/uploads/Rhyme/frdm-kl25z-ss.jpg FRDM-KL25Z
/media/uploads/Rhyme/frdm-k64f-ss.jpg FRDM-K64F
/media/uploads/Rhyme/nucleo-f411re-ss.jpg NUCLEO-F411RE

Files at this revision

API Documentation at this revision

Comitter:
Rhyme
Date:
Sat Mar 07 00:53:42 2015 +0000
Parent:
2:4b9260139892
Child:
4:6f3532a1a962
Child:
7:e58e106c6232
Commit message:
UniGraphic library version

Changed in this revision

SPI_TFT_ILI9341.lib Show diff for this revision Revisions of this file
TFTMenu.cpp Show annotated file Show diff for this revision Revisions of this file
TFT_fonts.lib Show diff for this revision Revisions of this file
UniGraphic.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
main.h Show annotated file Show diff for this revision Revisions of this file
menu.cpp Show annotated file Show diff for this revision Revisions of this file
view.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/SPI_TFT_ILI9341.lib	Wed Jan 21 00:53:09 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://developer.mbed.org/users/Rhyme/code/SPI_TFT_ILI9341/#61fa73a34834
--- a/TFTMenu.cpp	Wed Jan 21 00:53:09 2015 +0000
+++ b/TFTMenu.cpp	Sat Mar 07 00:53:42 2015 +0000
@@ -12,18 +12,18 @@
  * THE SOFTWARE.
  */
 #include "mbed.h"
-#include "SPI_TFT_ILI9341.h"
+#include <ILI9341.h>
 #include "SPI_STMPE610.h"
 #include "Arial12x12.h"
 #include "Arial24x23.h"
 #include "Arial28x28.h"
-#include "font_big.h"
+#include "Arial43x48_numb.h"
 #include "vt100.h"
 #include <string.h>
 
 #include "TFTMenu.h"
 
-extern SPI_TFT_ILI9341 TFT ;
+extern ILI9341 TFT ;
 extern SPI_STMPE610 TSC ;
 extern vt100 *tty ;
 
@@ -133,6 +133,7 @@
 
 void TFTMenuItem::draw(int offset_x, int offset_y)
 {
+    TFT.BusEnable(true) ;
     TFT.fillrect(left+offset_x, top+offset_y, right+offset_x, bottom+offset_y, Black) ;
     TFT.fillrect(left+offset_x, top+offset_y, right+offset_x, bottom+offset_y, menu_color) ;
     wait(0.1) ;
@@ -142,10 +143,12 @@
     TFT.set_font((unsigned char *)Arial12x12) ;
     wait(0.1) ;
     TFT.printf(label) ;
+    TFT.BusEnable(false) ;
 }
 
 void TFTRadioButton::draw(int offset_x, int offset_y)
 {
+    TFT.BusEnable(true) ;
     if (selected) {
         TFT.fillrect(left+offset_x, top+offset_y, right+offset_x, bottom+offset_y, Black) ;
         TFT.fillrect(left+offset_x, top+offset_y, right+offset_x, bottom+offset_y, alt_menu_color) ;
@@ -159,12 +162,15 @@
     } else {
         TFTMenuItem::draw(offset_x, offset_y) ;
     }
+    TFT.BusEnable(false) ;
 }
         
 
 void TFTMenuItem::highlight(int offset_x, int offset_y)
 {
+    TFT.BusEnable(true) ;
     TFT.rect(left+offset_x, top+offset_y, right+offset_x, bottom+offset_y, font_color) ;
+    TFT.BusEnable(false) ;
 /*
     TFT.fillrect(left+offset_x, top+offset_y, right+offset_x, bottom+offset_y, font_color) ;
     wait(0.1) ;
--- a/TFT_fonts.lib	Wed Jan 21 00:53:09 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/dreschpe/code/TFT_fonts/#76774250fcec
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/UniGraphic.lib	Sat Mar 07 00:53:42 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/teams/GraphicsDisplay/code/UniGraphic/#1bdfb971b2c1
--- a/main.cpp	Wed Jan 21 00:53:09 2015 +0000
+++ b/main.cpp	Sat Mar 07 00:53:42 2015 +0000
@@ -10,12 +10,12 @@
  * THE SOFTWARE.
  */
 #include "mbed.h"
-#include "SPI_TFT_ILI9341.h"
-#include "SPI_STMPE610.h"
+#include <ILI9341.h>
 #include "Arial12x12.h"
 #include "Arial24x23.h"
 #include "Arial28x28.h"
-#include "font_big.h"
+#include "Arial43x48_numb.h"
+#include "SPI_STMPE610.h"
 #include "vt100.h"
 #include "TFTMenu.h"
 #include "menu.h"
@@ -28,7 +28,9 @@
 Ticker timer ;
 
 DigitalOut backlight(PTA12) ;
-SPI_TFT_ILI9341 TFT(PIN_MOSI, PIN_MISO, PIN_SCLK, PIN_CS_TFT, PIN_BL_TFT, PIN_DC_TFT) ;
+ILI9341 TFT(SPI_8, 10000000, 
+    PIN_MOSI, PIN_MISO,  PIN_SCLK, 
+    PIN_CS_TFT, PIN_RESET_TFT, PIN_DC_TFT, "Adafruit2.8") ;
 SPI_STMPE610 TSC(PIN_MOSI, PIN_MISO, PIN_SCLK, PIN_CS_TSC) ;
 TFTMenuItem *menu[NUM_MAX_MENU] ;
 int numMenu = 0 ;
--- a/main.h	Wed Jan 21 00:53:09 2015 +0000
+++ b/main.h	Sat Mar 07 00:53:42 2015 +0000
@@ -22,6 +22,7 @@
 #define PIN_CS_SD       PTA4 
 #define PIN_CS_TSC      PTA13
 #define PIN_TSC_INTR    PTC9
+#define PIN_RESET_TFT   PTB10
 
 #elif defined (TARGET_KL46Z)
 #define PIN_MOSI        PTD6
@@ -54,7 +55,7 @@
 extern Ticker timer ;
 
 extern DigitalOut backlight ;
-extern SPI_TFT_ILI9341 TFT ;
+extern ILI9341 TFT ;
 extern SPI_STMPE610 TSC ;
 extern TFTMenuItem *menu[] ;
 extern int numMenu ;
--- a/menu.cpp	Wed Jan 21 00:53:09 2015 +0000
+++ b/menu.cpp	Sat Mar 07 00:53:42 2015 +0000
@@ -12,12 +12,12 @@
  * THE SOFTWARE.
  */
 #include "mbed.h"
-#include "SPI_TFT_ILI9341.h"
+#include <ILI9341.h>
 #include "SPI_STMPE610.h"
 #include "Arial12x12.h"
 #include "Arial24x23.h"
 #include "Arial28x28.h"
-#include "font_big.h"
+#include "Arial43x48_numb.h"
 #include "vt100.h"
 #include "TFTMenu.h"
 #include "menu.h"
--- a/view.cpp	Wed Jan 21 00:53:09 2015 +0000
+++ b/view.cpp	Sat Mar 07 00:53:42 2015 +0000
@@ -12,12 +12,12 @@
  * THE SOFTWARE.
  */
 #include "mbed.h"
-#include "SPI_TFT_ILI9341.h"
+#include <ILI9341.h>
 #include "SPI_STMPE610.h"
 #include "Arial12x12.h"
 #include "Arial24x23.h"
 #include "Arial28x28.h"
-#include "font_big.h"
+#include "Arial43x48_numb.h"
 #include "vt100.h"
 #include "TFTMenu.h"
 #include "main.h"
@@ -34,10 +34,13 @@
 void initTFT(void)
 {
     //Configure the display driver
+    TFT.BusEnable(true) ;
+    TFT.FastWindow(true) ;
     TFT.background(Black);
     TFT.foreground(White);
     wait(0.01) ;
     TFT.cls();
+    TFT.BusEnable(false) ;
 }
 
 
@@ -48,15 +51,19 @@
     x2 = left_margin + pane_w ;
     y1 = head_h + (pane_h + 5) * ch ;
     y2 = y1 + pane_h ;
+    TFT.BusEnable(true) ;
     TFT.fillrect(x1,y1,x2, y2, Black) ;
+    TFT.BusEnable(false) ;
 }
 
 void eraseGraphFrames(void)
 {
     int ch ;
+    TFT.BusEnable(true) ;
     for (ch = 0 ; ch < numAnalogIn ; ch++) {
         eraseChFrame(ch) ;
     }
+    TFT.BusEnable(false) ;
 }
 
 void drawChFrame(int ch)
@@ -66,6 +73,7 @@
     x2 = left_margin + pane_w ;
     y1 = head_h + (pane_h + 5) * ch ;
     y2 = y1 + pane_h ;
+    TFT.BusEnable(true) ;
     TFT.set_font((unsigned char*) Arial12x12);
     TFT.background(Black) ;
     TFT.foreground(White) ;
@@ -109,6 +117,7 @@
         y2 = y1 ;
         TFT.line(x1, y1, x2, y2, Blue) ;
     }
+    TFT.BusEnable(false) ;
 }
 
 bool inChFrame(int ch, int x, int y)
@@ -119,7 +128,7 @@
     x2 = left_margin + pane_w ;
     y1 = head_h + (pane_h + 5) * ch ;
     y2 = y1 + pane_h ;
-    if ((x1 <= x)&&(x < x2)&&(y1 <= y)&&(y < y2)) {
+    if ((x1 < x)&&(x < x2)&&(y1 < y)&&(y < y2)) { // on 5-Mar-2015 '=' removed
         result = true ;
     }
     return( result ) ;
@@ -149,9 +158,11 @@
 
 void drawGraphFrames(void)
 {
+    TFT.BusEnable(true) ;
     for (int i = 0 ; i < numAnalogIn ; i++ ) {
         drawChFrame(i) ;
     }
+    TFT.BusEnable(false) ;
 }
 
 void drawChart(void)
@@ -164,12 +175,14 @@
         timer.detach() ;
     }
 
+    TFT.BusEnable(true) ;
     for (i = 0 ; i < memLength ; i++ ) {
         for (ch = 0 ; ch < numAnalogIn ; ch++ ) {
             plotCh_line(prev_page, ch, i, Black) ; // erase prev
             plotCh_line(page, ch, i, White) ;
         }
     }
+    TFT.BusEnable(false) ;
     prev_page = page ;
     page = (page + 1)%2 ;
     sampling_status = ST_PRE_TRIG ;
@@ -183,6 +196,7 @@
 
 void printMode(void)
 {
+    TFT.BusEnable(true) ;
     TFT.locate(80, 200) ;
     TFT.background(Black) ;
 
@@ -193,6 +207,7 @@
         TFT.foreground(White) ;
         TFT.printf(" Running") ;
     }
+    TFT.BusEnable(false) ;
 }
 
 void printTimeDiv(void)
@@ -206,6 +221,7 @@
         dotval = us_interval % 100 ;
         sprintf(str, " %3d.%0d ms/div", ival, dotval) ;
     }
+    TFT.BusEnable(true) ;
     TFT.fillrect(65, 240, 175, 260, Black) ;
         
     TFT.background(Black) ;
@@ -213,11 +229,13 @@
 
     TFT.locate(65, 240) ;
     TFT.printf(str) ;
+    TFT.BusEnable(false) ;
 }
 
 void printTrigMode(void)
 {
     char str[60] ;
+    TFT.BusEnable(true) ;
     TFT.fillrect(65, 280, 235, 310, Black) ;
  
     TFT.background(Black) ;
@@ -232,21 +250,25 @@
     }
     TFT.locate(65, 280) ;
     TFT.printf(str) ;
+    TFT.BusEnable(false) ;
 }
 
 void printTrigLevel(void)
 {
     char str[16] ;
+    sprintf(str, " %.1f", trig_level) ;
+    TFT.BusEnable(true) ;
     TFT.locate(140, 280) ;
     TFT.background(Black) ;
     TFT.foreground(White) ;
-    sprintf(str, " %.1f", trig_level) ;
     TFT.printf(str) ;
+    TFT.BusEnable(false) ;
 }
 
 void eraseTrigMark(void)
 {
     int x1, x2, y1, y2 ;
+    TFT.BusEnable(true) ;
     x1 = left_margin - 3 ;
     x2 = left_margin + pane_w + 3 ;
     y1 = 1 ;
@@ -260,6 +282,7 @@
     y1 = 0 ;
     y2 = head_h + (pane_h + 5) * (2) + 1;
     TFT.fillrect(x1, y1, x2, y2, Black) ;
+    TFT.BusEnable(false) ;
 }
 
 void drawTrigPos()
@@ -268,6 +291,7 @@
     int x1, x2, y1, y2 ;
     int y_offset ;
 // draw down arrow
+    TFT.BusEnable(true) ;
     x1 = left_margin + trig_pos + 1 ;
     x2 = x1 ;
     y1 = 5 ;
@@ -300,6 +324,7 @@
     TFT.line(x1, y1, x2, y2, color) ;
     y2 = y1 + 3 ;
     TFT.line(x1, y1, x2, y2, color) ;
+    TFT.BusEnable(false) ;
 }
 
 void drawTrigMark(void)