なんとか受信もできるようになった。FT-817のダイアルを回すとArduinoの液晶の数字も同じように変化した。なかなかいい感じ。受信データにジョグダイアルに応じた数値を足して周波数を変化できるようにしたいところだが、残念ながら時間切れ。長くモニターを見ていると目が疲れる。残りは出張から帰ってきてから。明日から台湾に。
ここまでに作成したソースコード。
//Receive and dispaly frequency while potvalue is non zero value
// FreqDisp 2010/11/20
//
#include <LiquidCrystal.h>
//Constants for variable-register
#define POTENTIO 2 // ANALOG input for variable-register
#define POTVALUE_NUL 500 //variable-register center value
#define POTVALUE_NUL_ZONE 50 //variabe-register nul zone width
#define FACTOR 1 //variable-register conversion factor
#define SET_FREQ 01 //Command for sending frequency to FT-817
//Masks or BCDto BIN conversion
#define HighMask B11110000
#define LowMask B00001111
LiquidCrystal lcd(7,8,9,10,11,12,13);
// static
int incomingByte=0;
int i;
float potvalue; //return value of variable regisiter
int potentio_in; //AD data from the variable regisiter
int sensorPin = 2; // select the input pin for the potentiometer
byte Bcdvalue; //1 byte BCD value from FT-817
int Binvalue; //1 byte converted frequency data
int Up_Freq; //Upper frequency data
int Mega_Freq; //Mega heltz conponent
int Freq100k; //100kHz conponent
int Low_Freq; //Lower frequency data
long Freq; //Frequency (8 digits)
byte ftype; //Transmission type
char lcd_buff[7]; //LCD display buffer
int P[4]; //FT-817に送られるパラメータ群
void setup(){
Serial.begin(4800);
lcd.begin(2,16);
for(int i=0;i<=6;i++){
pinMode(i,OUTPUT);
}
lcd.clear();
}
void loop(){
get_pod();//read variable register
//lcd.setCursor(1,0);
//lcd.print(potvalue);
lcd.setCursor(9,1);
lcd.print("MHz");
// read data only when potvalue > 0
if(abs(potvalue) > 0){
//send receive fequency data command
Serial.print(0,BYTE); //dummy data
Serial.print(0,BYTE); //dummy data
Serial.print(0,BYTE); //dummy data
Serial.print(0,BYTE); //dummy data
Serial.print(3,BYTE); //reade frequency command
// send data only when you receive data:
while (Serial.available() > 0) {
// read upper frequency data:
Up_Freq=0;
for(i=0;i<2;i++){
Bcdvalue = Serial.read();//read data from the radio
bcdtobin();//1 byte bcd to bin conversion
Up_Freq=Up_Freq*100+Binvalue;//Upper 4 digits
}
// read lower frequency data
Low_Freq=0;
for(i=0;i<2;i++){//transform 4 byte bcd to bin
Bcdvalue = Serial.read();//read data from the radio
bcdtobin();//1 byte bcd to bin conversion
Low_Freq=Low_Freq*100+Binvalue;//Lower 4 digits
}
//display MHz digits
lcd.setCursor(0,1);
Mega_Freq=Up_Freq/10;
sprintf(lcd_buff,"%3d.",Mega_Freq);
lcd.print(lcd_buff);
//display 100kHz digit
Freq100k=Up_Freq-Mega_Freq*10;
lcd.print(Freq100k);
//display Lower frequency components
sprintf(lcd_buff,"%04d",Low_Freq);
lcd.print(lcd_buff);
//read frequency type
ftype=Serial.read();
lcd.setCursor(13,1);
switch(ftype){//display transmission mode
case 0: lcd.print("LSB");
break;
case 1: lcd.print("USB");
break;
case 2: lcd.print("CW");
break;
case 3: lcd.print("CWR");
break;
case 4: lcd.print("AM ");
break;
case 6: lcd.print("WFM");
break;
case 8: lcd.print("FM ");
break;
case 10: lcd.print("DIG");
break;
case 12: lcd.print("PKT");
break;
}
}
}
Freq=Up_Freq*10000L;
Freq=Freq+Low_Freq+potvalue;//Frequency 8digits
lcd.setCursor(0,0);
lcd.print(Freq);
bintobcd();
delay(50); //wait for sending next command
}
int get_pod(){
// KEYPAD input
potentio_in = analogRead(POTENTIO);
// Serial.println(potentio_in);
potvalue=(potentio_in -POTVALUE_NUL);
// Serial.println(potvalue);
if (abs(potvalue) < POTVALUE_NUL_ZONE)potvalue=0; //ポテンショが中央付近なら数値をゼロに。
potvalue= FACTOR*potvalue; //係数をかける。
}
// transforn 1 byte bcd(Bcdvalue) to bin(Binvalue)
int bcdtobin(){
int highvalue;
int lowvalue;
highvalue=(Bcdvalue & HighMask) >> 4; //Mask lower bists and shift 4 bits
lowvalue= Bcdvalue & LowMask; //Mask higher 4 bits
Binvalue=highvalue*10+lowvalue; //calculate binary value
}
//Transform Freq(long binary frequency) to BCD(P[1]-P[4])
int bintobcd(){
int bcd[8];
long Tfreq;
Tfreq=Freq;
//generate 8 BCD digits
for(i=0;i<8;i++){
bcd[i]=Tfreq % 10; //modulo 10
Tfreq=Tfreq/10;//shift 1 digit
}
//generate 4 sets of 2 BCD digits
for(i=0;i<4;i++){
P[i]=(bcd[i*2]<<4)+bcd[i*2+1];
}
}
int SendFreq(){
int k;
for(k =0 ; k < 4 ; k++) Serial.print(P[k],BYTE); //周波数の送出
Serial.print(SET_FREQ,BYTE);
}
ここまでに作成したソースコード。
//Receive and dispaly frequency while potvalue is non zero value
// FreqDisp 2010/11/20
//
#include <LiquidCrystal.h>
//Constants for variable-register
#define POTENTIO 2 // ANALOG input for variable-register
#define POTVALUE_NUL 500 //variable-register center value
#define POTVALUE_NUL_ZONE 50 //variabe-register nul zone width
#define FACTOR 1 //variable-register conversion factor
#define SET_FREQ 01 //Command for sending frequency to FT-817
//Masks or BCDto BIN conversion
#define HighMask B11110000
#define LowMask B00001111
LiquidCrystal lcd(7,8,9,10,11,12,13);
// static
int incomingByte=0;
int i;
float potvalue; //return value of variable regisiter
int potentio_in; //AD data from the variable regisiter
int sensorPin = 2; // select the input pin for the potentiometer
byte Bcdvalue; //1 byte BCD value from FT-817
int Binvalue; //1 byte converted frequency data
int Up_Freq; //Upper frequency data
int Mega_Freq; //Mega heltz conponent
int Freq100k; //100kHz conponent
int Low_Freq; //Lower frequency data
long Freq; //Frequency (8 digits)
byte ftype; //Transmission type
char lcd_buff[7]; //LCD display buffer
int P[4]; //FT-817に送られるパラメータ群
void setup(){
Serial.begin(4800);
lcd.begin(2,16);
for(int i=0;i<=6;i++){
pinMode(i,OUTPUT);
}
lcd.clear();
}
void loop(){
get_pod();//read variable register
//lcd.setCursor(1,0);
//lcd.print(potvalue);
lcd.setCursor(9,1);
lcd.print("MHz");
// read data only when potvalue > 0
if(abs(potvalue) > 0){
//send receive fequency data command
Serial.print(0,BYTE); //dummy data
Serial.print(0,BYTE); //dummy data
Serial.print(0,BYTE); //dummy data
Serial.print(0,BYTE); //dummy data
Serial.print(3,BYTE); //reade frequency command
// send data only when you receive data:
while (Serial.available() > 0) {
// read upper frequency data:
Up_Freq=0;
for(i=0;i<2;i++){
Bcdvalue = Serial.read();//read data from the radio
bcdtobin();//1 byte bcd to bin conversion
Up_Freq=Up_Freq*100+Binvalue;//Upper 4 digits
}
// read lower frequency data
Low_Freq=0;
for(i=0;i<2;i++){//transform 4 byte bcd to bin
Bcdvalue = Serial.read();//read data from the radio
bcdtobin();//1 byte bcd to bin conversion
Low_Freq=Low_Freq*100+Binvalue;//Lower 4 digits
}
//display MHz digits
lcd.setCursor(0,1);
Mega_Freq=Up_Freq/10;
sprintf(lcd_buff,"%3d.",Mega_Freq);
lcd.print(lcd_buff);
//display 100kHz digit
Freq100k=Up_Freq-Mega_Freq*10;
lcd.print(Freq100k);
//display Lower frequency components
sprintf(lcd_buff,"%04d",Low_Freq);
lcd.print(lcd_buff);
//read frequency type
ftype=Serial.read();
lcd.setCursor(13,1);
switch(ftype){//display transmission mode
case 0: lcd.print("LSB");
break;
case 1: lcd.print("USB");
break;
case 2: lcd.print("CW");
break;
case 3: lcd.print("CWR");
break;
case 4: lcd.print("AM ");
break;
case 6: lcd.print("WFM");
break;
case 8: lcd.print("FM ");
break;
case 10: lcd.print("DIG");
break;
case 12: lcd.print("PKT");
break;
}
}
}
Freq=Up_Freq*10000L;
Freq=Freq+Low_Freq+potvalue;//Frequency 8digits
lcd.setCursor(0,0);
lcd.print(Freq);
bintobcd();
delay(50); //wait for sending next command
}
int get_pod(){
// KEYPAD input
potentio_in = analogRead(POTENTIO);
// Serial.println(potentio_in);
potvalue=(potentio_in -POTVALUE_NUL);
// Serial.println(potvalue);
if (abs(potvalue) < POTVALUE_NUL_ZONE)potvalue=0; //ポテンショが中央付近なら数値をゼロに。
potvalue= FACTOR*potvalue; //係数をかける。
}
// transforn 1 byte bcd(Bcdvalue) to bin(Binvalue)
int bcdtobin(){
int highvalue;
int lowvalue;
highvalue=(Bcdvalue & HighMask) >> 4; //Mask lower bists and shift 4 bits
lowvalue= Bcdvalue & LowMask; //Mask higher 4 bits
Binvalue=highvalue*10+lowvalue; //calculate binary value
}
//Transform Freq(long binary frequency) to BCD(P[1]-P[4])
int bintobcd(){
int bcd[8];
long Tfreq;
Tfreq=Freq;
//generate 8 BCD digits
for(i=0;i<8;i++){
bcd[i]=Tfreq % 10; //modulo 10
Tfreq=Tfreq/10;//shift 1 digit
}
//generate 4 sets of 2 BCD digits
for(i=0;i<4;i++){
P[i]=(bcd[i*2]<<4)+bcd[i*2+1];
}
}
int SendFreq(){
int k;
for(k =0 ; k < 4 ; k++) Serial.print(P[k],BYTE); //周波数の送出
Serial.print(SET_FREQ,BYTE);
}