Saturday, April 30, 2016

10 Milliwats on WSPR

I saw this posting by NT7S recently and figured this would be something easy to try. I already had several Si5351 breakout boards and a low-pass filter - so why not?  Jason describes how to set up everything on this page. You will need to download the sketch and the Python script. The Python script (ntpserial.py) loads the time stamp from your computer to the serial port of your Arduino compatible board.  I had to download Python 2.7 as I couldn't get it to run using Python 3.5.  I think with a little modification to the script you could get it to do so if, unlike me, you know what you're doing. Just make sure you change the serial port in the Python script to reflect the com port that is connected to your Arduino board.

DEVICE = 'com4'            # Change this as necessary in Windows
DEVICE = '/dev/tty20'     #or for the Linux equivalent

If you have a Raspberry Pi sitting around doing nothing, it is a good choice to run the ntpserial.py script (if connected to the internet). Python already exists on the Raspberry Pi or most any other computer running Linux.
note: on my raspberry pi I issued this command: ls -ltr /dev|grep -i tty*
and got back ttyACM0 which is called a "dialout" port. It works just fine.

This seems to be a waste of resources since this could probably be done on the PI alone.  But, what could be simpler? I've been using the Beaglebone Black to supply the time signal for the past three weeks.

Make these changes to your Arduino sketch to reflect your own call and locator.

unsigned long freq = 14097100UL;                 //I use 20 meters
//unsigned long freq = 10140200UL;              // so these other two freqs are
//unsigned long freq = 7040100UL;                // commented out
char call[7] = "AK2B";                                   // Change this
char loc[5] = "FN30";                                     // Change this

My setup looks like this
:
And this morning my 10mw hunk of ether burning rf brought me this little surprise:

Saturday, June 20, 2015

Teensy 3.1 VFO with encoder and si5351 board

This view adds the encoder and an Si5351 breakout board. The one shown is an Adafruit board but for my own project I'm using Jason's (NT7S) latest breakout board. The display is from Banggood. The display needs to have J1 jumpered to enable 3v3 regulator.

***Just a note to say that I blew up my Teensy 3.1 using this configuration. It worked quite well for a while and then it just stopped working and became very hot. I'm not sure why? Maybe it was a problem with the display and the Si5351 board running from the Teensy 3v3 pin. The Teensy 3.1 3v3 pin has a 100ma max current available. I wasn't using any current limiting resistance in the backlight of the display, so according to Adafruit, I would be drawing about 50 ma. Truthfully, I didn't measure the current draw from the si5351 board.  Anyway, I'm now using a new Teensy 3.1 board without the breakout board and running the display and si5351 board from a separate 3.3v regulator. 

This all points out an issue that I probably should have brought up in the very beginning - I'm not that bright! 

**7/6/15 I blew up another Teensy. Now I'm really confused. Both of the blown ones get hot and have no voltage on the 3.3V pin. I assume the processor is fried. This even after removing the TFT display and the si5351 breakout board to an offline 3.3V regultor!!

**I think I found the problem. The back light (BL) of the display is connected to pin D0 which most likely can't source the current needed (~50ma). I will connect the back light along with the breakout board to an external 3.3v source. I will clean up this drawing soon.

**7/9/15 I made the following measurements.
Teensy with program running and no pins attached draws 31.7 mA.
Teensy with program running and all pins attached 36 mA. (BL & VCC & si5351 powered separately)
The TFT display plus the si5351 breakout board draw 25 mA.
The TFT back light draws 19 mA. The spec for the i/o pins is 25 mA but, that is a maximum rating. (According to this spec sheet on page 10).
However, Cosford on the PJRC Forum pointed out "Have a look at page 13. I think by default the Teensy core defaults the pins to high drive strength, which gives you 9mA to play with. But as you say, I think you can drive higher loads (possibly up to 25 mA as you've pointed out for short periods. Note, 'Maximum' current single pin limit)."
After all this, I could easily run the backlight(BL), the si5351 board and the TFT display(VCC) from the 3v3 output pin since it's only about 44 ma total. Teensy 3.3 volt pin is 100 mA maximum. Since I need to have a 5 volt regulator board for the transmitter anyway, I just added a 150ma 3v3 regulator to be safe.

I'll get this sorted out eventually. I like the Teensy 3.1 - it's small and fast, has lots of pins and plenty of program space. In this case, I'm glad the errors were self-inflicted.

**7/11/15 Updated drawing to reflect the use of an external 3v3 regulator. In my project I use a 5 volt regulator as input to the  3v3 regulator.




Today we will be stealing...I mean borrowing code from Rich Heslip, VE3MKC. Rich made up a really cool Teensy SDR which you can see in this video.
There are some things in this code that are not used just yet but it does compile and work with my Teensy 3.1, encoder and TFT display. You should be able to just cut and paste the code into a new sketch.

I had an awful time trying to figure out why the display flickered when the vfo changed frequency until I found a reference in an Adafruit tutorial which explained the setTextColor command was overloaded (meaning it can take one or two variables). The overloaded variable was the background color. So, in my code, "display.setTextColor(S6D02A1_Green , S6D02A1_BLUE)" in the function "display_frequency()" the display doesn't flicker. If I leave out the S6D02A1_BLUE part, it gets really ugly and upsetting. Actually, if I had followed my own advise and looked in the Adafruit_GFX.h file, I would have seen two commands for setTextColor.

#include <Adafruit_GFX.h>    // Core graphics library
#include <Adafruit_S6D02A1.h> // Hardware-specific library
#include <SPI.h>
#include <Wire.h>
#include <si5351.h>
//#include <Encoder.h> //not used
#include <Rotary.h>
//#include <Bounce2.h> //not used

// This examples uses the hardware SPI only. Non-hardware SPI
// is just too slow (~8 times slower!)

//#define  BACKLIGHT  0  // backlight control signal -  not used anymore
#define sclk 13 // Don't change
#define mosi 11  // Don't change
#define cs   2
#define dc   3
#define rst  1  // you can also connect this to the Arduino reset
#define ENCODER_BTN  16  //I use this instead of TuneSW

Adafruit_S6D02A1 display = Adafruit_S6D02A1(cs, dc, mosi, sclk, rst);  // Invoke custom library

Rotary tune(15, 14); //pins 15 and 14 used for encoder
Si5351 si5351;
//const int8_t TuneSW =18;    // low for fast tune - encoder pushbutton(I don't use this)
volatile uint32_t vfo = 1420000000ULL / SI5351_FREQ_MULT; //start freq - change to suit
volatile uint32_t LSB = 899950000ULL;
volatile uint32_t USB = 900150000ULL;
volatile uint32_t bfo = 900150000ULL; //start in usb
volatile uint32_t radix = 100;
volatile uint32_t lastVFO;
int myOldList[9]= {0,0,0,0,0,0,0,0,0};
uint32_t Bands[] {
1800000L, 3500000L, 7000000L, 10100000L, 14200000L, 18065000L, 21000000L, 24890000L, 28000000L
}; //not used at the moment
boolean changed_f = 0;
String tbfo = "USB";

void setup(void) {

  Serial.begin(9600); // debug console
  Wire.begin();
  //pinMode(BACKLIGHT, INPUT_PULLUP); // yanks up display BackLight signal - not used
  pinMode(ENCODER_BTN, INPUT_PULLUP);  // tuning rate = high "radix"
  attachInterrupt(14, chk_encoder, CHANGE);  //I attach interrupts to encoder pins
  attachInterrupt(15, chk_encoder, CHANGE);  //but use the same Interrupt Service Routine                                                                                           //(chk_encoder())
  si5351.init(SI5351_CRYSTAL_LOAD_8PF,0);
  //si5351.set_correction(157);
  // Set CLK0 to output vfo plus IF frequency with a fixed PLL frequency
  si5351.set_pll(SI5351_PLL_FIXED, SI5351_PLLA);
  si5351.set_freq((vfo * SI5351_FREQ_MULT) + bfo, SI5351_PLL_FIXED, SI5351_CLK0);
  //volatile uint32_t vfoT = (vfo * SI5351_FREQ_MULT) + bfo; //test stuff
  tbfo = "USB"; //for lower left display display
  // Set CLK2 to output bfo frequency
  si5351.set_freq( bfo, 0, SI5351_CLK2);

  display.initR(INITR_BLACKTAB);   // initialize a S6D02A1S chip, black tab
  SPI.setClockDivider(SPI_CLOCK_DIV2); // crank up the spi
  uint16_t time = millis();
  display.setRotation(1); // 0 - Portrait, 1 - Lanscape
  display.fillScreen(S6D02A1_BLACK);
  display.setTextWrap(true);
  delay(500);
  //testdrawrects(S6D02A1_GREEN);
  delay(500);
  setUpDisplay();
  display_frequency();
  display_radix();
}

void loop() {

 if(changed_f)     //this flag is changed to yes(1) when the encoder changes
 {  
    display_frequency();
    //synt.simple_set_frequency(CLK0, frequency*F_MULT);
    si5351.set_freq((vfo * SI5351_FREQ_MULT) + bfo, SI5351_PLL_FIXED, SI5351_CLK0);
     si5351.drive_strength(SI5351_CLK0,SI5351_DRIVE_8MA);
    if (vfo >= 10000000ULL & tbfo != "USB")
    {
      bfo = USB;
      tbfo = "USB";
      si5351.set_freq( bfo, 0, SI5351_CLK2);
      Serial.println("We've switched from LSB to USB");
    }
    else if (vfo < 10000000ULL & tbfo != "LSB")
    {
      bfo = LSB;
      tbfo = "LSB";
      si5351.set_freq( bfo, 0, SI5351_CLK2);
      Serial.println("We've switched from USB to LSB");
    }
    changed_f = 0;        //and cleared back to no(0) after updates are made to the si5351
 }
 if (get_button())
  {
    switch (radix)
    {
      case 1:
        radix = 10;
        break;
      case 10:
        radix = 100;
        break;
      case 100:
        radix = 1000;
        break;
      case 1000:
        radix = 10000;
        break;
      case 10000:
        radix = 100000;
        break;
      case 100000:
        radix = 1;
        break;
    }
    display_radix();
  }
}

// show frequency
void display_frequency() {
    //lastVFO = vfo;
    char string[80];   // print format stuff  - I always have to look this up :)
    sprintf(string,"%d.%03d.%03d",vfo/1000000,(vfo-vfo/1000000*1000000)/1000,
          vfo%1000 );
    display.setCursor(35, 5);
    display.setTextColor(S6D02A1_GREEN,S6D02A1_BLUE); //full display blanking -
    display.setTextSize(2);                                                              //you really need the
    display.print(string);                                                                  //2nd parameter to keep the
}                                                                                                     //display from flickering

void set_frequency(short dir)
{                                        
  if(dir == 1)                 //This routine is called by the Interrupt Service Routine chk_encoder()
    vfo += radix;            //which sets the vfo to its new value up or down plus or minus the
  if(dir == -1)               //the step size(radix)  
    vfo -= radix;
  changed_f = 1;          //it also sets this yes/no flag to yes to tell the loop that there has been a
}                                  //a change in frequency

void chk_encoder(){                                               //This routine (ISR) is called by the Arduino
   //Serial.println("inside encoder");                       // every time the encoder changes. Interrupts
    unsigned char result = tune.process();               // tell microprocessors, "STOP WHAT YOU
    if (result) {                                                          // ARE DOING!....and take care of me before
    //Serial.println(result == DIR_CW ? 1 : -1);     //going any further"
    if (result == DIR_CW)                                      //calls set_frequency() with a +1 or -1
    set_frequency(1);
  else if (result == DIR_CCW)
    set_frequency(-1);  
  }
}
void setUpDisplay(){
    //display.fillRect(1,1,158,25,S6D02A1_BLUE);
    //display.Color565(245, 179, 190);
    display.fillScreen(S6D02A1_BLUE);
    //display.fillRect(0,5,158,23,S6D02A1_BLUE);
    display.fillRect(1,1,13,24,S6D02A1_RED);
    //display.fillRect(1,1,13,24,Color565);
    display.drawFastVLine(0, 0, 25, S6D02A1_WHITE);
    display.drawFastVLine(159, 0, 25, S6D02A1_WHITE);
    display.drawFastHLine(0,0,160,S6D02A1_WHITE);
    display.drawFastHLine(0,25,160,S6D02A1_WHITE);  
    display.setCursor(1, 5);
    display.setTextSize(2);
    display.setTextColor(S6D02A1_GREEN);
    display.println("A");
//    display.setCursor(1, 90);
//    display.setTextSize(1);
//    display.setTextColor(S6D02A1_GREEN);
//    display.println("USB     RIT off     100Hz");

}

/**************************************/
/* Read the button with debouncing    */
/**************************************/
boolean get_button()
{
  if(!digitalRead(ENCODER_BTN))
  {
    delay(20);
    if(!digitalRead(ENCODER_BTN))
    {
      while(!digitalRead(ENCODER_BTN));
      return 1;
    }
  }
  return 0;
}

void display_radix()
{
  //display.fillRect(0,90,158,24,S6D02A1_BLUE);
  display.setTextSize(1);
  display.setTextColor(S6D02A1_GREEN,S6D02A1_BLUE);
  display.setCursor(110, 85);  
  //display.println("USB     RIT off     100Hz");
  switch (radix)
  {
    case 1:
      display.print("    1");
      break;
    case 10:
      display.print("   10");
      break;
    case 100:
      display.print("  100");
      break;
    case 1000:
      display.print("   1k");
      break;
    case 10000:
      display.print("  10k");
      break;
    case 100000:
      //display.setCursor(10, 1);
      display.print(" 100k");
      break;
      //case 1000000:
      //display.setCursor(9, 1);
      //display.print("1000k"); //1MHz increments
      //break;
  }
  display.print("Hz");
}

Friday, May 15, 2015

AK2B NT7S KK7B W7ZOI WB6DHW Si5351 receiver

This video was made a couple of months back. There are links in the notes to the various boards used  if you watch it on YouTube.


Sunday, May 3, 2015

N2HTT's 3 Band VFO

In the world of the Si5351 there are some interesting projects evolving from hams around the world. In the U.S., Jason, NT7S has started an App Notes page to his Etherkit website. The first app  is an Antenna Analyzer.
Another item that has recently appeared is by Mike Aiello, N2HTT which is a 3 band VFO using a si5351 and an Arduino.

You get a much better understanding of how to use an Arduino with an Si5351, and of course, programming, by looking over the code of indviduals who really know what they are doing.


I made up my own version of the VFO using the same ATMega 2560 board with an Adafruit OLED and one of Jason's original breakout boards. The code for Mike's VFO can be found on the link above. The original code was for a 2560 but later code will work with an UNO.


Monday, April 6, 2015

Multi-Featured VFO

Download MultiFeaturedVFO.ino
Download Rotary.Zip (click on Down Arrow at top of page)
Jason's Arduino Si5351 Library (click on Download Zip) and install it directly into the new Arduino IDE as mentioned in my last post.
Hardware Layout for this program can be found here.

//------------------------------- Set Optional Features here --------------------------------------
//Remove comment (//) from the option you want to use. Pick only one
#define IF_Offset //Output is the display plus or minus the bfo frequency // this line will be used
//#define Direct_conversion //What you see on display is what you get
//#define FreqX4  //output is four times the display frequency
//--------------------------------------------------------------------------------------------------

You can output frequencies up to 160Mhz. Keep this in mind when you use the 4X frequency option.
You can also tune in 1Hz increments if you so desire.
Also, I use clk0 for VFO output and clk2 for BFO.

Jason's latest library has a calibration sketch that can be accessed by:

You can easily adjust the frequency correction using the Serial Monitor and the keyboard. Make note of the offset and put it into si5351.set_correction(); in the VFO sketch. The correction is no longer stored in the board EEPROM so do not comment out the set_correction line as I had mentioned in the past. Also when using the current hardware setup, nothing will change on the LCD while adjusting the frequency - only on a frequency counter.
Looking at the above screen you will notice three Si5351 libraries in my "user libraries" folder. The Adafruit_Si5351 is not a problem since the header file uses a different name. The "Si5351" and "Si5351Arduino-Jason" share the same header file name. I did get an error that said something like "multiple libraries were found for si5351.h files - you must die". Both were Jason's newer library but the one, "Si5351Arduino-Jason" had all the newer upadates and examples so I deleted the "Si5351" folder.

Wednesday, April 1, 2015

Arduino now allows you to add Zipped libraries


It seems with the newer version of the Arduino IDE you can now download a library and add it without having to unzip it (Add .ZIP Library...). It also adds the library to the proper place in the Arduino User directory.  


Further, it seems to not care about hyphenated folder names. I download the latest version of NT7S's Si5351 library into my downloads directory and by adding the library as above and it worked just fine. User libraries are now listed in a section called "Contributed libraries" which shows up when you click "Include Library" on the above menu. This should make things a little less confusing.



Sunday, March 29, 2015

Si5351 VHF VFO

Link to  VHF_VFO.ino
I can tune up to 160Mhz. Output with default current setting is about -10dbm.
 /*
  This entire program is taken from Jason Mildrum, NT7S and Przemek Sadowski, SQ9NJE and Ben     Buxton.
  
  ***The following code has been modified to use the updated library of NT7S. 
  As of this date, the library is still undergoing changes so be aware of that.
  This code was tested on an Arduino Uno ONLY and it works if you setup your
  Equally important is that you make sure that Jason's new library REPLACES any existing
  Si5351 libraries in places that the Arduino IDE will look for it. Remove the existing Si5351 folder   in the "Arduino/Libraries" folder and put it in another folder for safe keeping in case you need to use it again.  I made a folder called Lib_Temp to put user libraries not in use. If you get errors
  it will most likely be for this reason. Please spend the time to resolve this problem.
  MAKE SURE THE ARDUINO IDE IS CLOSED WHEN MAKEING CHANGES TO THE LIBRARY.
  For help on the proper place to put libraries look here:
  Jason's new library will break existing code using his older library.
  */

  #include <Rotary.h>
  #include <si5351.h>
  #include "Wire.h"
  #include <LiquidCrystal.h>
 
  #define OLED_RESET 4
  #define ENCODER_A    3                      // Encoder pin A
  #define ENCODER_B    2                      // Encoder pin B
  #define ENCODER_BTN  11
  #define LCD_RS 5
  #define LCD_E        6
  #define LCD_D4 7
  #define LCD_D5 8
  #define LCD_D6 9
  #define LCD_D7 10

  LiquidCrystal lcd(LCD_RS, LCD_E, LCD_D4, LCD_D5, LCD_D6, LCD_D7);       // LCD - pin assignement in
  Si5351 si5351;
  Rotary r = Rotary(ENCODER_A, ENCODER_B);

  volatile uint32_t frequency0 = 1000000000L / SI5351_FREQ_MULT; //10Mhz - change to suit your needs
  //just take care to count the right number of zeros.
//  volatile uint32_t frequency1 = 9000000L;
//  volatile uint32_t frequency2 = 10000000L;
  volatile uint32_t radix = 100;
  boolean changed_f = 0;

  /**************************************/
  /* Interrupt service routine for      */
  /* encoder frequency change           */
  /**************************************/
  ISR(PCINT2_vect) {
    unsigned char result = r.process();
    if (result == DIR_CW)
      set_frequency(1);
    else if (result == DIR_CCW)
      set_frequency(-1);
  }
  /**************************************/
  /* Change the frequency               */
  /* dir = 1    Increment               */
  /* dir = -1   Decrement               */
  /**************************************/
  void set_frequency(short dir)
  {
    if(dir == 1)
      frequency0 += radix;
    if(dir == -1)
      frequency0 -= radix;
    changed_f = 1;
  }
  /**************************************/
  /* Read the button with debouncing    */
  /**************************************/
  boolean get_button()
  {
    if(!digitalRead(ENCODER_BTN))
    {
      delay(20);
      if(!digitalRead(ENCODER_BTN))
      {
        while(!digitalRead(ENCODER_BTN));
        return 1;
      }
    }
    return 0;
  }

  /**************************************/
  /* Displays the frequency             */
  /**************************************/
    void display_frequency()
  {
    uint16_t f, g;
 
    lcd.setCursor(3, 0);
    f = frequency0 / 1000000;
    if(f<10)
      lcd.print(' ');
    lcd.print(f);
    lcd.print('.');
    f = (frequency0 % 1000000)/1000;
    if(f<100)
      lcd.print('0');
    if(f<10)
      lcd.print('0');
    lcd.print(f);
    lcd.print('.');
    f = frequency0 % 1000;
    if(f<100)
      lcd.print('0');
    if(f<10)
      lcd.print('0');
    lcd.print(f);
    lcd.print("Hz");
  }

  /**************************************/
  /* Displays the frequency change step */
  /**************************************/
  void display_radix()
  {
    lcd.setCursor(10, 1);
    switch(radix)
    {
      case 10:
        lcd.print("  10");
        break;
      case 100:
        lcd.print(" 100");
        break;
      case 1000:
        lcd.print("  1k");
        break;
      case 10000:
        lcd.print(" 10k");
        break;
      case 100000:
        lcd.print("100k");
        break;
        case 1000000:
        lcd.setCursor(9, 1);
        lcd.print("1000k"); //1MHz increments
        break;
    }
    lcd.print("Hz");
  }


  void setup()
  {
    lcd.begin(16, 2);                                                    // Initialize and clear the LCD
    lcd.clear();
    Wire.begin();
    // Start serial and initialize the Si5351 with load capacitance and crystal freq
//0 will provide default freq of 25Mhz. If you have a 27MHz crystal put in 27000000
si5351.init(SI5351_CRYSTAL_LOAD_8PF, 0); //you could measure your crystal and put it here to    correct for errors.
// Set CLK0 to output 10 MHz with a fixed PLL frequency
si5351.set_pll(SI5351_PLL_FIXED, SI5351_PLLA);
//set frequency with 1 Hz resolution
si5351.set_freq(frequency0 * SI5351_FREQ_MULT, SI5351_PLL_FIXED, SI5351_CLK0);
 
     pinMode(ENCODER_BTN, INPUT_PULLUP);
     PCICR |= (1 << PCIE2);           // Enable pin change interrupt for the encoder
     PCMSK2 |= (1 << PCINT18) | (1 << PCINT19);
     sei();
     display_frequency();  // Update the display
     display_radix();
  }


  void loop()
  {
    // Update the display if the frequency has been changed
    if(changed_f)
    {
      display_frequency();    
      si5351.set_freq(frequency0 * SI5351_FREQ_MULT, 0, SI5351_CLK0);
      changed_f = 0;
    }
 
    // Button press changes the frequency change step
    if(get_button())
    {
      switch(radix)
      {
        case 10:
          radix = 100;
          break;
        case 100:
          radix = 1000;
          break;
        case 1000:
          radix = 10000;
          break;
          case 10000:
          radix = 100000;
          break;
        case 100000: //change these lines to tune in 1MHz increments
          radix = 1000000;
          break;
        case 1000000:
          radix = 10;
          break;
      }
      display_radix();
    }
  }