Skip to main content

Arduinos embedded within homebrew test gear ~ N6QW Part II

The Mystery Is Solved!

As a recap, in my prior post I was just starting to investigate the use of Arduino's that could be embedded into homebrew test gear. There are many programs floating around and many incredible, and might I add, sophisticated pieces of test equipment that can be built employing the Arduino. Many of these are in Altoids Tins.
 
But I simply wanted to learn how to generate and display data beyond push that there and pull this here. Thus I thought a simple display of a sine wave would be an easy entry for me to learn about how to generate the data and more importantly how to display the data. I should confess that my days of learning about trigonometric functions was 6 decades ago and thus I can claim that many of my brain cells have died along the way so I am missing some critical pieces of information. Which I was.
 
The plot shown in Part I are not sine waves! They look like a sine wave because  I wanted so badly for them to look like a sine. Here is why they are not and I must thank Greg a ham down in VK land for providing the key to unlock the Gordian Knot!
 
First an excerpt from Purple Math: [It all has to do with Degrees, Degrees Minutes Seconds (DMS) and Radians. The real eye opener was Radians.]
 
"Why do we have to learn radians, when we already have perfectly good degrees? Because degrees, technically speaking, are not actually numbers, and we can only do math with numbers. This is somewhat similar to the difference between decimals and percentages. Yes, "83%" has a clear meaning, but to do mathematical computations, you first must convert to the equivalent decimal form, 0.83. "
 
Thus my equations simply plugged in x as a numerical number form 14 to 320 as in sin(x). My failure was to understand that the Arduino only works with radians. Massimo Banzai in his book on Getting Started with Arduino clearly states that the values for sin(x) must be in radians.
 
Greg provided me two lines of code to try in the sketch which actually does this conversion and of course it involves the use of Pi or more specifically Pi/180 which equals 0.01745329252. Making those changes results in a curve that looks like this. Now that is a sine wave! Thanks Greg!
 
 
The next photo fills in the area under the curve with hundreds of red lines.
 
 
Here is the revised code and note these two changes:

const double deg2rad = 0.01745329252;

y = 50*sin(deg2rad*x);

/* From N6QW using the 240 X 320 TFT Color display
This is to test displating graphical information such as you would have with test instrument
*/
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <TFT_ILI9340.h>
#if defined(__SAM3X8E__)
#undef __FlashStringHelper::F(string_literal)
#define F(string_literal) string_literal
#endif
#define __CS 10
#define __DC 9
#define __RST 8
// Color definitions
#define BLACK   0x0000
#define BLUE    0x001F
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0 
#define WHITE   0xFFFF
TFT_ILI9340 tft = TFT_ILI9340(__CS, __DC, __RST);
#include "Wire.h"
int val = 0;
int val1 = 0;
int x = 0;
int y = 0;
int old_val = 0;
int old_val1 = 0;
const double deg2rad = 0.01745329252;
void setup() {
 
 
  tft.begin();
  #if defined(__MK20DX128__) || defined(__MK20DX256__)
  tft.setBitrate(24000000);
  #endif
        tft.fillScreen(0x07F0); // testing switching background colors
        tft.fillScreen(WHITE); // 0x07F0 = lt green, 0xF810 = rose, 0xF840 = rust, 0xF820 = orange
        tft.setRotation(1); // landsacape versus portrait
       
       
        tft.drawLine(14,0,14,230, BLACK); //X axiz
        tft.drawLine (14,230, 300, 230, BLACK); // Y axis
        tft.drawRect( 14, 118, 300, 2, GREEN); //centerline of plot & the 2 is the width of the rectangle --makes it look like a FAT line
   
 
}
void loop()
    
{   
 
 for(int x = 0; x <320; x++){ //sets the range of values to plot along the X axis
 
 
   y =50*sin(deg2rad*x);
   old_val = x ; // for connecting lines to the dots
   old_val1 = y  ; //for connecting lines to the dots
  
  tft.drawRect(x,y +120,  2, 2, MAGENTA); // the y+120 puts the y values in the center of the screen null this out for two tone test pattern
 
   delay(1);
  
 }
 {
 for(int x = 0; x <320; x++){ //sets the range of values to plot along the X axis

   y =50*sin(deg2rad*x);
   old_val = x ; // for connecting lines to the dots
   old_val1 = y  ; //for connecting lines to the dots

 tft.drawLine( x, y + 120,old_val  , 120 - old_val1, RED
 ); // null this out for sine wave
  delay (1);
  }
   
   }
 }
 
This was a great exercise for me because now I learned something (again) that is critical to displaying math data on a TFT screen. Thanks again Greg.
 
73's
Pete N6QW

Popular posts from this blog

2019 ~ What is the simplest homebrew SSB Transceiver that can be built?

4/27/2019 The Future of our Hobby is Here! Forget those simple rigs with homebrew crystal filters, cranky IRF510's and the analog VFO's. SDR is the wave that is building strength just like a Tsunami. With the Soft Rock V6.3 SMD Version + RRPi2 With the Omnia SDR and RPi2 Pete N6QW How Simple & How Cheap can you  build a Homebrew SSB Transceiver? 4/26/2019 --- I just converted my websites from an obsolete Windows Based Server with GoDaddy to their cPanel (Linux). This was a cost issue as a one year renewal of the Windows Server would buy three years on the cPanel. GoDaddy is discouraging the use of what they call the Obsolete Windows System. So I had to migrate and reload the whole pastapete.com, jessystems.com and the n6qw.com sites to the Linux based servers. Some files and links got lost in the translation --so you might not be able to see everything! Essentially I have  to open every link to verify that it works --that may take some time

New Technology for 2020 ~ The Hermes Lite 2.0 SDR Transceiver

  The Hermes Lite 2.0 SDR Transceiver. November 7th, 2020 ~ It's Settled! It is done! The stain of the Trump era is soon to be removed! Thanks to all who voted. The Voice of the People has been heard.  Congratulations to President Elect Biden and Vice President Elect Harris. Pete N6QW November 3rd, 2020 -- IT WAS THE MOUSE   We all know this is Dump Trump  Day. Go out and vote! It was the mouse! Back in 1999 I stupidly was one of the very first to purchase a Ten Tec Pegasus. Never buy the first batch of a new model.  Touted as the world's first computer controlled radio , actually I think the Kachina 505 was really the first. But the Pegasus was fraught with problems including a trip back to the Smokey Mountains. I was using an older Windows 95 machine to control the Pegasus and that may be a co-conspirator. Well after many calls to TT -- finally someone who has some smarts told me: Fix your station ground, Make all leads short and Buy stock in a ferrite bead company. I did all

The Next Project Updated 10/10/2022! The rubber has hit the pavement!

The Next Project... A 2022 Transceiver. 10/10/2022 My Apologies. It is with regret that I will be terminating any further work on this project. My caregiver duties have over time become a greater time sink and it is almost impossible to build something working only 10-15 minutes at a time spread out over a day. I apologize for not getting it from design ideas to complete hardware. Most likely I have built the last transceiver I will ever build. Thanks for riding along. My website https://www.n6qw.com/  has the pdf of the postings and I will leave this blog page as is. 73's Pete N6QW 10/05/2022 Still Alive! Regrettably my caregiver duties have overtaken any free time so not much progress. But I am hopeful yet this week I will cut at least one board. A PSA from N6QW.  Think of it like Mary Jo has a "crink" in her back and unable to get in the backseat of the 57 VW Beetle. A bit of a setback but not forever.  Seems like the hired caregiver had a small emergency and not able