Author Archives: admin

Arduino based Kenwood DG5 emulator for my TS-520S

Here’s a quick video of my DG5 emulator prototype buttoned up in a project box.

Still waiting on my PCB’s to arrive on the slow boat from China.  I already have changes to make – the first version PCB has the 3 RCA jacks for the 3 signals from the TS-520S on the opposite side from the Arduno’s USB – not exactly the best for mounting in a box.  And I also have added the display since I sent in the design, so I’ll have to add that in as well.  The “shield” is getting a bit tight with the DIP IC’s and new requirements, I might either go to SMD devices (for the IC’s at least) or just make the shield bigger that an Arduino.  This might actually be an advantage, as a bigger shield would allow me to slide it in a Hammond type aluminum extrusion chassis, with the Arduino plugging in on top, upside down.

Got myself one of the AS9850 DDS modules that are available on eBay for around $10.  Looking at making an external VFO for the TS-520 with one of these, so a bigger box might be a good idea.

DG5 Update – now with LCD display!

Today I added a display, so now my the DG5 emulator actually emulates a DG5 in function – a digital display of your frequency.  I also built some Arduino shield PCB’s using Eagle and have sent them off to Itead in China, should have them back in a couple of weeks.

Here’s the display in action:

Using a parallel LCD display because the frequency counter code uses an 8 bit Timer and the only 16 bit Timer on the 328 – most of the serial based libraries use the 16 bit timer as well, causing a conflict.

A Kenwood DG-5 emulated on Arduino

A few months ago, I bought a Kenwood TS-520S. The Kenwood hybrid’s are beautiful radios, and the TS-520 is the first radio I was on the air with (on amateur HF bands) while I was in High School in the early 80’s.  So when I had an opportunity to pick one up locally, I jumped at it.

I have had a great time playing around with it and ragchewing. It takes a bit more work than my K3 or TS-2000 (tuning, calibrating) but that’s the beauty – it’s like an older car with points, condensers, and a carburetor – takes some more tweaking, but you can fiddle with it easily. I replaced the HV caps, adjusted the calibrator, and cleaned the switches and pots, but that’s about it. It just works.

I came across a site called Toddfun.com while doing some TS-520 searches, and found a series of very well documented posts (with in depth videos) about  building a Kenwood DG-5 type display for the TS-520.  The Kenwood DG-5 was an optional digital display for the TS-520/820, and on the used market they go for more than I paid for the radio!  He was using the Arduino platform, something I have been using for a few years here.  I thought, “I can do this!”, but instead of a display, I wanted to have it talk to my computer so my logging program (DXLab) could read the frequency of the radio.

There’s lots I could do better, and the Mega 328 isn’t the best platform to be doing frequency counting, updating a display, and servicing a serial port at the same time.  The frequency counter needs the limited internal timers on the 328 which limits use of I2C, SPI, and software serial libraries as far as I can see.  Nevertheless, getting the TS-520 to talk to my computer is what I set out to do, and it works beautifully!

A quick and dirty demo of it:

I don’t have a schematic for it, if you watch Todd’s video’s you can figure it out.  Basically, the signals are buffered and conditioned by the TI PLL’s, the (HFO frequency needs to be pre-scaled as it’s outside the range of the Arduino counter), and the 3 are mux’ed into the Arduino on pin 5.

Arduino DG-5 code:

/* 

Kenwood DG5 digital display emulator, sort of.

Stephen Leander, KV6O
August 22, 2014

No display in this revision, outputs Kenwood Commander commands on the Serial/USB port for a logging program (DXLab's Commander)
No idea if it will work with other programs because I haven't tested anything else!

Got the idea from Todd Harrison's website, Toddfun.com, where he outlined and built an Adrunio DG-5 emulator, with the plans of using this to display
the frequency, just like the DG-5.

http://www.toddfun.com/2013/02/07/arduino-frequency-display-for-kenwood-ts-520s-hf-ham-radio-part-1/

Counter code based on Arduino timer code by Nick Gammon
http://www.gammon.com.au/forum/?id=11504

Emulates a TS-790 for DX Commander, based on input from Dave, AA6YQ:

 From Dave AA6YQ, DXLab's author:
 From: dxlab@yahoogroups.com [mailto:dxlab@yahoogroups.com] Sent: Tuesday, August 05, 2014 10:42 PM To: dxlab@yahoogroups.com Subject: [dxlab] Kenwood

 >>>If your emulator responds to the ID; command with 

 ID007;

 >>>Commander will think its controlling a TS-790. The only other commands to which your emulator will then have to respond are IF; and FB;

 >>>Note: Commander pays attention to the following bytes of the radio's response to an IF; command:

 3-13: VFO A frequency
 29: RX vs TX status
 30: Mode
 31: VFO selection
 33: split status

 >>>Operation won't be convenient unless your emulator can correctly report the radio's mode.

See http://www.kenwood.com/i/products/info/amateur/ts_480/pdf/ts_480_pc.pdf for more on Kenwood command set.

8/22/14 - Version 1.0 Prototyped the circuit using 3 TI PLL's (74HC4046A's), a 74HC93 counter for prescaling the HFO, and 74HC153 for selecting the
signal (VFO, BFO, or HFO) to be counted by the Arduino on pin 5.

*/

//#define DEBUG //Uncomment for debugging

volatile unsigned long timerCounts;
volatile boolean counterReady;

// internal to counting routine
unsigned long overflowCount;
unsigned int timerTicks;
unsigned int timerPeriod;

unsigned long vfo = 0;
unsigned long bfo = 0;
unsigned long hfo = 0;

void startCounting (unsigned int ms)
 {
 counterReady = false; // time not up yet
 timerPeriod = ms; // how many 1 mS counts to do
 timerTicks = 0; // reset interrupt counter
 overflowCount = 0; // no overflows yet

 // reset Timer 1 and Timer 2
 TCCR1A = 0;
 TCCR1B = 0;
 TCCR2A = 0;
 TCCR2B = 0;

 // Timer 1 - counts events on pin D5
 TIMSK1 = bit (TOIE1); // interrupt on Timer 1 overflow

 // Timer 2 - gives us our 1 mS counting interval
 // 16 MHz clock (62.5 nS per tick) - prescaled by 128
 // counter increments every 8 µS.
 // So we count 125 of them, giving exactly 1000 µS (1 mS)
 TCCR2A = bit (WGM21) ; // CTC mode
 OCR2A = 124; // count up to 125 (zero relative!!!!)

 // Timer 2 - interrupt on match (ie. every 1 mS)
 TIMSK2 = bit (OCIE2A); // enable Timer2 Interrupt

 TCNT1 = 0; // Both counters to zero
 TCNT2 = 0; 

 // Reset prescalers
 GTCCR = bit (PSRASY); // reset prescaler now
 // start Timer 2
 TCCR2B = bit (CS20) | bit (CS22) ; // prescaler of 128
 // start Timer 1
 // External clock source on T1 pin (D5). Clock on rising edge.
 TCCR1B = bit (CS10) | bit (CS11) | bit (CS12);
 } // end of startCounting

ISR (TIMER1_OVF_vect)
 {
 ++overflowCount; // count number of Counter1 overflows
 } // end of TIMER1_OVF_vect

//******************************************************************
// Timer2 Interrupt Service is invoked by hardware Timer 2 every 1ms = 1000 Hz
// 16Mhz / 128 / 125 = 1000 Hz

ISR (TIMER2_COMPA_vect)
 {
 // grab counter value before it changes any more
 unsigned int timer1CounterValue;
 timer1CounterValue = TCNT1; // see datasheet, page 117 (accessing 16-bit registers)
 unsigned long overflowCopy = overflowCount;

 // see if we have reached timing period
 if (++timerTicks < timerPeriod)
 return; // not yet

 // if just missed an overflow
 if ((TIFR1 & bit (TOV1)) && timer1CounterValue < 256)
 overflowCopy++;

 // end of gate time, measurement ready

 TCCR1A = 0; // stop timer 1
 TCCR1B = 0; 

 TCCR2A = 0; // stop timer 2
 TCCR2B = 0; 

 TIMSK1 = 0; // disable Timer1 Interrupt
 TIMSK2 = 0; // disable Timer2 Interrupt

 // calculate total count
 timerCounts = (overflowCopy << 16) + timer1CounterValue; // each overflow is 65536 more
 counterReady = true; // set global flag for end count period
 } // end of TIMER2_COMPA_vect

String inputString = ""; // a string to hold incoming command date
boolean stringComplete = false; // whether the string is complete

void setup ()
 {
 pinMode(2, OUTPUT); // for signal select on the 74HC153. Using Pins 2 and 3.
 pinMode(3, OUTPUT);

 Serial.begin(9600);
 // reserve 200 bytes for the inputString:
 inputString.reserve(200);

 // end of setup

 }

void loop ()
 {
 for (int x=0; x < 3; x++){ // Loop thru the 3 signals to count the signals.
 if (x==0) { //Select VFO
 digitalWrite(2, LOW);
 digitalWrite(3, HIGH);
 }
 if (x==1) { //Select BFO
 digitalWrite(2, HIGH);
 digitalWrite(3, LOW);
 }

 if (x==2) { //Select HFO
 digitalWrite(2, LOW);
 digitalWrite(3, LOW);
 } 

delay (20); //settle time

 // stop Timer 0 interrupts from throwing the count out
 byte oldTCCR0A = TCCR0A;
 byte oldTCCR0B = TCCR0B;
 TCCR0A = 0; // stop timer 0
 TCCR0B = 0; 

 startCounting (100); // how many mS to count for

 while (!counterReady)
 { } // loop until count over

 // adjust counts by counting interval to give frequency in Hz
 float frq = (timerCounts * 1000.0) / timerPeriod;

// Serial.print (" freq: ");
// Serial.print ((unsigned long) frq);

 if (x==0)vfo=frq; // load frequency's into vfo, bfo, and hfo.
 if (x==1)bfo=frq;
 if (x==2)hfo=(frq*8);

#ifdef DEBUG // for debugging and monitoring the results.
Serial.print("VFO: ");
Serial.print (vfo);
Serial.print(" BFO: ");
Serial.print (bfo);
Serial.print(" HFO: ");
Serial.print (hfo);
Serial.print (" FREQ: ");
Serial.println (hfo-(bfo+vfo));

#endif

 // restart timer 0
 TCCR0A = oldTCCR0A;
 TCCR0B = oldTCCR0B;

 }

 // Check serial port to see if we have a command
 if (stringComplete) {

 if (inputString == "ID;") { //ID the radio as a "ID007" - Kenwood TS790. There is no TS-520S. ;-)
 Serial.print("ID007;");
 }
 else if (inputString == "FB;"){ // Probably not needed as Commander uses the "IF" command, used for debugging..
 Serial.print("FB00014195000;");
 }
 else if (inputString == "IF;"){

 if ((hfo-(bfo+vfo)) > 9000000){ // Used 9Mhz as the cutoff so I could properly format the string with the additiona digit returned above 10Mhz.
 Serial.print ("IF000");
 Serial.print (hfo-(bfo+vfo));
 Serial.print ("000000000000000020000000;"); // The "2" is the mode, above 9Mhz it returns "USB"
 }
 else
 {
 Serial.print ("IF0000");
 Serial.print (hfo-(bfo+vfo));
 Serial.print ("000000000000000010000000;"); // Mode set to 1 for "LSB".
 }
 } 

 // clear the string:
 inputString = "";
 stringComplete = false;

 // end of loop

 }
 } 

 /*
 SerialEvent occurs whenever a new data comes in the
 hardware serial RX. This routine is run between each
 time loop() runs, so using delay inside loop can delay
 response. Multiple bytes of data may be available.
 */

void serialEvent() {
 while (Serial.available()) {
 // get the new byte:
 char inChar = (char)Serial.read();
 // add it to the inputString:
 inputString += inChar;
 // if the incoming character is a newline, set a flag
 // so the main loop can do something about it:
 if (inChar == ';') { // Look for ";" - this is the Kenwood command terminator.
 stringComplete = true;
 }
 }
} 

[wpdm_file id=2 title=”true desc=”true”]

 

PHP Weather Station Scripts for Ultimeter 2100 (CWOP)

Back in the summer of 2013 I was looking for a replacement for my laptop that was sending weather updates from my Peet Bros U2100 to the CWOP network.  My laptop died, and I thought this would be the perfect application for my Raspberry Pi.  I found a script the the U800 (see post below for more) and got it working for the U2100, but it needed a few tweaks to work properly with the U2100.  Specifically, the changes I made were:

  • Changed time to localtime() – be sure your rasperry pi is set to the correct timezone.
  • Changed humidity as  the U2100 reports 3 digits.
  • Changed wind reporting as U2100 reports in kph, not mph.
  • Changed temp reporting to handle negative numbers.

This code has been working for my U2100 for over 6 months with few problems, such as
the negative temps not being handled correctly being the last thing fixed. I wasn’t
aware of the issue till it got cold enough!   See the original post for more on how to use it with the RPi, many thanks to CloudHopper who provided it.

My weather station’s data can be seen HERE. Every once and a while I see the local news show my stations data on the air – cool!

[wpdm_file id=1]

Raspberry Pi – low powered computing fun!

I have been playing around with my Raspberry Pi for a while here, my original plan was to use it as the high level control for a Arduino based repeater controller (handling the low level repeater stuff (timers, CWID, etc.), but I had my home Windows based server die on me and I needed something to update the CWOP network with my weather station data.   The server I had was a Windows 2003 server running on an old T42 IBM Thinkpad with an external USB drive. It died a somewhat noisy death as the CPU cooling fan finally seized (made an awful racket for about 24 hours before giving up the ghost).  I had performed surgery once before to replace the fan, but as I didn’t really need a full Windows server to perform a simple web update every 8 minutes, and I also have a 1TB LG-NAS device to act as a file server – so why have this power hungry machine to perform this simple task?  Enter the Raspberry Pi…

I found a post about using PHP on the Raspberry Pi to update the CWOP network from data collected from a Peet Bros U800 – I was using a Peet Bros U2100, so I figured I’d give it a try.
I made a few changes as the wind speed was being reported in kph, not mph, the humidity was being reported incorrectly at 100% (needs to report “00”), and I set it up to report local time.  Success!  The RasPi was now uploading my WX reports to CWOP every 8 minutes and taking a fraction of the power. It’s a low powered machine on 2 levels – doesn’t draw much current (about 2.5W), but it’s not a high performance workstation either.  But it’s perfect for this application – no need to tie up a power hungry computer 7/24 to perform a simple task.

Since this is barely using the RasPi capabilities, I am playing around with other tasks it can perform – currently it’s also hosting an inexpensive SDR module (Realtek RTL2832U based USB TV tuner) to receive some local FM data and decode it.  I am still not 100% on the legality here (it’s public safety POCSAG pages) – I need to clear this up before I take it much further. I am a subscriber to this paging system as a firefighter, and I have an application in mind (fire station paging “receiver”), so I am a legitimate user – but I still want to make sure this is OK.

More on how to do this can be found here.

Random thoughts

Election Day is finally here. Not going to spew any politics, there’s enough of that on TV, radio, Facebook, my telephone, mail, everywhere. Looking forward to the regular annoying ads. Looks amazingly close!

The Arduino repeater is running here, the code seems to be stable, been running for about 6 months here (not continuously!). Looking forward to getting it talking to the Raspberry Pi, and have been looking at the Svxlink software for Echolink integration plus more perhaps!

 

 

Hello world part deux?

Humm, my first page disappeared and the standard, “Hello World!” has re-appeared.  Let’s see if my edit sticks.

The purpose of this site will be to document my Arduino inspired repeater controller (it’s a HAM thing) and it’s interface with the Raspberry Pi.