This sketch reads the channel selector on my 979 through a 9555 i/o expander and outputs to the pll through a level shifter.
It starts at the lowest possible channel and works it way up 40 channels in sequential order with no skips or channel misalignments (26.815 to 27.205 on my radio).
That's all it does for now, I'll eventually have it set a band flag as you cross the 40/01 band border and then have it continue on up or down, so we should end up with continuous tuning and the channel it was on when powered down should persist when powered back up.
I used the same index to array method on this version. There is actually a 45 channel spread between CB channel 1 and 40 due to the 5 skipped channels in the lower 23, the channel selector can't ever select them but it screws the index up if you don't have the array size match the spread, so I put blank place holders in the extra channel slots.
// CBduino Lite V1_2
// 2/17/15
// Written on an Arduino Nano.
//
// Experimental, this sketch assumes a level shifter is hooked up and an I2C 9555 i/o port expander
// is hooked up. The port expander can interface directly to the channel selector on a Galaxy 979,
// it may not to other radios, if not using a 979 proceed with caution!
//
// Not overly commented, just playin' and thought others may want to too.
#include <Wire.h> // required library for i2c interface
#define PCA9555 0x20 // i2c address of board, run i2c scanner sketch to get the address
#define IN_P0 0x00 // Read Input port0
#define IN_P1 0x01 // Read Input port1
#define OUT_P0 0x02 // Write Output port0
#define OUT_P1 0x03 // Write Output port1
#define CONFIG_P0 0x06 // Configuration port0 configures the direction of the I/O pins 0 is output 1 is input
#define CONFIG_P1 0x07 // Configuration port1 configures the direction of the I/O pins 0 is output 1 is input
byte byte_read;
int channel; // holds PLL setting for the desired channel
int output_to_pll[7] = {8,7,6,5,4,3,2}; // Pins assigned as digital outputs to the level shifter.
// The array below holds the PLL settings that are sent to the PLL for a
// particular channel reodering the list will reorder how the radio tunes
byte CHNL[45] [7]= {
{1,0,0,0,0,0,0}, // 01 0
{1,0,0,0,0,0,1}, // 02 1
{1,0,0,0,0,1,0}, // 03 2
{0,0,0,0,0,0,0}, // -- 3
{1,0,0,0,0,1,1}, // 04 4
{1,0,0,0,1,0,0}, // 05 5
{1,0,0,0,1,0,1}, // 06 6
{1,0,0,0,1,1,0}, // 07 7
{0,0,0,0,0,0,0}, // -- 8
{1,0,0,0,1,1,1}, // 08 9
{1,0,0,1,0,0,0}, // 09 10
{1,0,0,1,0,0,1}, // 10 11
{1,0,0,1,0,1,0}, // 11 12
{0,0,0,0,0,0,0}, // -- 13
{1,0,0,1,0,1,1}, // 12 14
{1,0,0,1,1,0,0}, // 13 15
{1,0,0,1,1,0,1}, // 14 16
{1,0,0,1,1,1,0}, // 15 17
{0,0,0,0,0,0,0}, // -- 18
{1,0,0,1,1,1,1}, // 16 19
{1,0,1,0,0,0,0}, // 17 20
{1,0,1,0,0,0,1}, // 18 21
{1,0,1,0,0,1,0}, // 19 22
{0,0,0,0,0,0,0}, // -- 23
{1,0,1,0,0,1,1}, // 20 24
{1,0,1,0,1,0,0}, // 21 25
{1,0,1,0,1,0,1}, // 22 26
{1,0,1,0,1,1,1}, // 24 27
{1,0,1,1,0,0,0}, // 25 28
{1,0,1,0,1,1,0}, // 23 29
{1,0,1,1,0,0,1}, // 26 30
{1,0,1,1,0,1,0}, // 27 31
{1,0,1,1,0,1,1}, // 28 32
{1,0,1,1,1,0,0}, // 29 33
{1,0,1,1,1,0,1}, // 30 34
{1,0,1,1,1,1,0}, // 31 35
{1,0,1,1,1,1,1}, // 32 36
{1,1,0,0,0,0,0}, // 33 37
{1,1,0,0,0,0,1}, // 34 38
{1,1,0,0,0,1,0}, // 35 39
{1,1,0,0,0,1,1}, // 36 40
{1,1,0,0,1,0,0}, // 37 41
{1,1,0,0,1,0,1}, // 38 42
{1,1,0,0,1,1,0}, // 39 43
{1,1,0,0,1,1,1} // 40 44
};
//
void setup() {
for (int i=2; i <= 8; i++){
pinMode(i, OUTPUT); // sets pin ports 2 through 8 as an output
}
Wire.begin(PCA9555); // join expansion board to i2c buss
write_io (CONFIG_P0, B00000000); //defines all pins on Port0 are outputs
write_io (OUT_P0, B00000000); //sets all pins on Port0 to low
write_io (CONFIG_P1, B11111111); //defines all pins on Port1 are inputs
}
//
void loop() {
check_what_channel(IN_P1); // this function reads the channel selector and returns the channel array index
generate_pll_divisor(); // this function generates the pll divisor settings for the channel selected
}
//
//****Functions****//
//
void check_what_channel(int ReadPort) {
Wire.beginTransmission(PCA9555);
Wire.write(ReadPort);
Wire.endTransmission();
Wire.requestFrom(PCA9555,1);
byte_read = Wire.read();
byte_read = byte_read ^ B10000000;
channel = map(byte_read,79,123,0,44);
}
//
void generate_pll_divisor() {
for(int a=0; a < 7; a++){
digitalWrite(output_to_pll[a], CHNL[channel][a]);}
}
//
void write_io(int command, int value)
{
Wire.beginTransmission(PCA9555);
Wire.write(command),Wire.write(value);
Wire.endTransmission();
}