LCD TFT 144" / 128 *128
Arduino Nano
Pulsadores sin retención NA (a necesidad)
Alimentación externa por USB, se usa para el Arduino y el LCD.
Si usan protoboard cables para conexión.
Puntas para el osciloscopio.
Imaginación: Para el armado definitivo según sus gustos.
Lo bueno es que no se necesitan tantos materiales para realizarlo y obtendremos una herramienta útil.
El funcionamiento es simple de alguna manera. Solo se toman los datos obtenidos y se representan en pantalla de manera que se puedan apreciar de una manera más cómoda. Esto es para cuando tenemos una frecuencia alta y las ondas se juntan tanto que no podemos ver con claridad las distintas faces. Entonces lo que hacemos básicamente es estirar la señal.
Hice un gráfico para que se entienda mejor el concepto:
tb1 y tb2 hacen referencia a timebase 1(normal) y tb2 a timebase 2 (multiplicado por 2) o presionar el pulsador y pasarlo a X2. Los valores del gráfico son ilustrativos.
Ahora, relacionado con lo anterior, esta el tema del límite de lectura que es el: ¿cual es la frecuencia máxima? Ya se toco el tema en el video. Pero quiero dejarles esto para que sea más facil de entender:
#include <Adafruit_GFX.h>
#include <Adafruit_ST7735.h>
#include <SPI.h>
#define TFT_CS 10
#define TFT_RST 9 // you can also connect this to the Arduino reset
// in which case, set this #define pin to 0!
#define TFT_DC 8
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
// Option 2: use any pins but a little slower!
#define TFT_SCLK 13 // set these to be whatever pins you like!
#define TFT_MOSI 11 // set these to be whatever pins you like!
//Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST);
/********************************************/
#define SCREENWIDTH 128
#define SCREENHEIGHT 128
#define CHARWIDTH 5
#define CHARHEIGHT 7
#define AXISWIDTH (2 + 1) // axis will show two-pixel wide graph ticks, then an empty column
#define VISIBLEVALUEPIXELS (SCREENWIDTH - AXISWIDTH) // the number of samples visible on screen
#define NUMVALUES (2 * VISIBLEVALUEPIXELS) // the total number of samples (take twice as many as visible, to help find trigger point
#define TRIGGER_ENABLE_PIN 3 // set this pin high to enable trigger
#define SCREEN_UPDATE_ENABLE_PIN 4 // set this pin high to freeze screen
#define BASE_PIN 5
#define DIGI_PIN 6
byte values[NUMVALUES]; // stores read analog values mapped to 0-127 (can't store 0-1024 in one byte)
byte values2[NUMVALUES]; // stores read analog values mapped to 0-127 (can't store 0-1024 in one byte)
byte* frontBuffer = values;
byte* backBuffer = values2;
int pos = 0; // the next position in the value array to read
int count = 0; // the total number of times through the loop
int factorAmpliacion = 1; // factor de ampliacion NO ESTA EN USO ACTUALMENTE POR SER POCO PRACTICO PUEDE ELIMINARSE ESTA VARIABLE SIN PROBLEMA
int tiempoBase = 1; // tiempo base
unsigned long readStartTime = 0; // time when the current sampling started
int lastStart = 0; // the sample at which drawing started last time (need to know this to clear the old line properly)
bool isStop = false;
boolean digi = false; // set this to true if you are only interested in digital signals, to get MUCH more speed
// Used by vsprintf.
char buffer[32];
/********************************************/
// Dibuja el tiempo en la base de la pantalla
void displayln(int x, int y, const char* format, ...)
{
// Borra el texto anterior
tft.setTextColor(ST7735_BLACK);
tft.setCursor(x,y);
tft.println(buffer);
va_list args;
va_start(args, format);
vsprintf(buffer, format, args);
va_end(args);
tft.setTextColor(ST77XX_YELLOW);
tft.setTextSize(1);
tft.setCursor(x,y);
tft.println(buffer);
}
// Dibuja el factor de multiplicacion del tiempo base en la pantalla
void displaytb(int x, int y, const char* valor, ...)
{
// Borra el texto anterior
tft.setTextColor(ST7735_BLACK, ST77XX_WHITE);
tft.setCursor(x,y);
tft.println(tiempoBase);
va_list args;
va_start(args, valor);
vsprintf(buffer, valor, args);
va_end(args);
tft.setTextColor(ST77XX_MAGENTA, ST77XX_WHITE);
tft.setTextSize(1);
tft.setCursor(x,y);
tft.println(buffer);
}
// Dibuja las lineas verticales en la pantalla
void drawAxis()
{
byte div = SCREENHEIGHT / 6;
//Linea Azul
for (int y = 0; y < 3; y++)
{
tft.drawFastHLine( 0 , y = div*3, 127, ST7735_BLUE);
}
for (int y = 0; y < 3; y++)
{
int x=0;
tft.drawFastHLine( x , y * div , 127, ST7735_WHITE);
}
for (int y = 4; y < 7; y++)
{
int x=0;
tft.drawFastHLine( x , y * div , 127, ST7735_WHITE);
}
}
void dibujarEjesVerticales()
{
byte div = SCREENWIDTH / 6;
//Linea Roja
for (int x = 0; x < 3; x++)
{
tft.drawFastVLine( x = div*3, 0, 127, ST7735_RED);
}
for (int x = 0; x < 3; x++)
{
int y=0;
tft.drawFastVLine( x * div, y , 115, ST7735_WHITE);
}
for (int x = 4; x < 7; x++)
{
int y=0;
tft.drawFastVLine( x * div, y , 115, ST7735_WHITE);
}
}
void estaPresionado()
{
// En los siguientes IF´s controlamos la subida y bajada del factor de multiplicacion del timebase
if ( digitalRead(BASE_PIN) && tiempoBase <=6 && isStop == false)
{
tiempoBase = tiempoBase + 1;
tft.fillScreen(ST7735_BLACK);
if (tiempoBase == 6)
{
isStop = true;
}
// while(digitalRead(BASE_PIN)){tft.fillScreen(ST7735_BLACK);}
}
if ( digitalRead(BASE_PIN) && tiempoBase == 6 && isStop == true)
{
tiempoBase = 1;
tft.fillScreen(ST7735_BLACK);
if (tiempoBase == 1)
{
isStop = false;
}
// while(digitalRead(BASE_PIN)){tft.fillScreen(ST7735_BLACK);}
}
// Cambio para lecturas digitales
if ( digitalRead(DIGI_PIN) )
{
if(digi == false)
{
digi = true;
tft.fillScreen(ST7735_BLACK);
}else if(digi == true){ digi =false;tft.fillScreen(ST7735_BLACK);}
}
}
// Draws the sampled values
void drawValues()
{
int start = 0;
float mag = SCREENHEIGHT / 128.0; // 128 because sample values are 0-127
if ( true || digitalRead(TRIGGER_ENABLE_PIN) ) {
// Find the first occurence of zero
for (int i = 0; i < NUMVALUES; i++) {
if ( backBuffer[i] != 0 ) {
// Now find the next value that is not zero
for (; i < NUMVALUES; i++) {
if ( backBuffer[i] == 0 ) {
start = i;
break;
}
}
break;
}
}
if ( start >= VISIBLEVALUEPIXELS ) {
for (int i = 0; i < VISIBLEVALUEPIXELS; i++) {
tft.drawPixel(i + AXISWIDTH, SCREENHEIGHT - 1 - (frontBuffer[i + lastStart] * mag), ST7735_WHITE);
}
return;
}
}
// clear the old line and draw the new
for (int i = 1; i < (VISIBLEVALUEPIXELS-1); i++) {
tft.drawLine(((i-1) + AXISWIDTH)*tiempoBase , SCREENHEIGHT - 1 - (frontBuffer[(i-1) + lastStart] * mag ), (i + AXISWIDTH)*tiempoBase , SCREENHEIGHT - 1 - (frontBuffer[i + lastStart] * mag), ST7735_BLACK);
tft.drawLine(((i-1) + AXISWIDTH)*tiempoBase , SCREENHEIGHT - 1 - (backBuffer[(i-1) + start] * mag),(i + AXISWIDTH)*tiempoBase, SCREENHEIGHT - 1 - (backBuffer[i + start] * mag), ST7735_GREEN);
}
// swap sample buffers
byte* tmp = backBuffer;
backBuffer = frontBuffer;
frontBuffer = tmp;
lastStart = start;
}
// Shows the time taken to sample the values shown on screen
void drawFrameTime(unsigned long us)
{
displayln(SCREENWIDTH/2 - 4*CHARWIDTH, SCREENHEIGHT - 1.5*CHARHEIGHT, "%ld us", us);
}
// Muestra el factor de ampliacion del basetime
void timeBase(unsigned long tb)
{
displaytb(SCREENWIDTH/6 - 4*CHARWIDTH, SCREENHEIGHT/6 - 2.5*CHARHEIGHT, "%ld tb",tb);
}
/********************************************/
void setup(void) {
tft.initR(INITR_GREENTAB);
tft.fillScreen(ST7735_BLACK);
drawAxis();
buffer[0] = 0;
//pinMode(TRIGGER_ENABLE_PIN, INPUT);
pinMode(SCREEN_UPDATE_ENABLE_PIN, INPUT);
pinMode(BASE_PIN, INPUT);
pinMode(DIGI_PIN, INPUT);
}
void sampleValues() {
// set the analog reference (high two bits of ADMUX) and select the
// channel (low 4 bits). this also sets ADLAR (left-adjust result)
// to 0 (the default).
ADMUX = (DEFAULT << 6) | (0 & 0x07);
//ADCSRA &= ~(ADPS0 | ADPS1 | ADPS2);
ADCSRA &= ~(ADPS2);
if ( digi ) {
for (int i = 0; i < NUMVALUES; i++) {
backBuffer[i] = PINC;
delayMicroseconds(5); // change this as necessary to alter the duration of the sampling pass
}
for (int i = 0; i < NUMVALUES; i++) {
backBuffer[i] = backBuffer[i] > 0 ? 64 : 0; // a value of 64 is half-way in the 0-127 range we are using
}
}
else {
for (int i = 0; i < NUMVALUES; i++) {
//start conversion
_SFR_BYTE(ADCSRA) |= _BV(ADSC);
// ADSC is cleared when the conversion finishes
while (bit_is_set(ADCSRA, ADSC));
uint8_t low = ADCL;
uint8_t high = ADCH;
backBuffer[i] = (high << 5) | (low >> 3);
delayMicroseconds(150); // change this as necessary to alter the duration of the sampling pass
}
}
}
/********************************************/
void loop() {
if ( !digitalRead(SCREEN_UPDATE_ENABLE_PIN) )
{
readStartTime = micros();
sampleValues();
unsigned long totalSampleTime = (micros() - readStartTime) / 2;
// Display the data on screen
timeBase(tiempoBase);
drawValues();
drawFrameTime(totalSampleTime);
}
estaPresionado();
dibujarEjesVerticales();
drawAxis();
}
Adafruit_GFX.h
Adafruit_ST7735.h
SPI.h