Page 1 of 2

SDR Tuning Knob

Posted: Sat Jan 20, 2018 8:19 pm
by WeakSingal3o3
Ok, let me start off by saying i have only a little bit of programming expereince from over 20 years ago and its beyond rusty. I would love to learn to code for arduino and such, but for that i consider myself mostly a noob and have tried to follow this post i found googling.

http://www.kd2kog.com/2016/07/500-tunin ... druno.html

Apparently parts of the code have been omitted and from what i can tell its code corresponding to keyboard combinations. needed to make the encoder work smoothly or properly? I managed to get the Tiny85 board, but only had a encoder laying around from another project which had the detent removed. I figured that should work unless this is specific code to the encoder listed in the post. In which case, i'll have to buy one of those still i suppose, but im having trouble even getting the code to test properly let alone upload to the board. I tried changing the missing code sections to what i thought were correct "code" taken from the trinket library file. Any help is and would be MUCH appreciated :)

Thank you!

Re: SDR Tuning Knob

Posted: Mon Jan 22, 2018 2:38 pm
by mikexeno
I will see if I can dig up my old code from that blog post. It's been a while.
FYI...Your better off with a Arduino Leonardo vs the ATTINY85

Re: SDR Tuning Knob

Posted: Mon Jan 22, 2018 2:40 pm
by mikexeno
The reason why I left code out was that I wanted people to explore vs the usual copy and pasting of my code.

Re: SDR Tuning Knob

Posted: Mon Jan 22, 2018 3:34 pm
by WeakSingal3o3
oh, i understand Mike, and believe me, im trying to learn lol :) I have tons of other projects and ideas in my head if i could just get the code part straight on my end. So ive been reading and even found some android apps to help with the learning curve. I know VERY little C and mostly knew pascal, lmao, so i can somewhat read the code and understand whats happening but apparently just not enough. Ive been trying to figure this knob code out for a month or two now, how sad is that?..

I'll order up the other board if it works better. I should be ok with my encoder though? I Started off with the RTL dongles, and though they were fun, they were hard to use due to drift and such and kind of put me off from SDR for a few years. After i saw your videos on youtube and some other possibilities for the RSP2, i figured it was worth another shot. And WOW, what a difference! Has RE-Sparked my interest in radio again and im hoping to get at least a tech license before the pool changes again in June lol.

Anyhow, i appreciate your help, and this wonderful little black box! Cant wait to some day try it as a panadapter as well.

Thanks again Mike, very much appreciated!

Re: SDR Tuning Knob

Posted: Mon Jan 22, 2018 8:08 pm
by mikexeno
I should have my code on a external hard drive. I have to take a look. We (Myself and Jon) did this a while back. I used a leonardo clone.

https://youtu.be/LG4n6_A8OxU

Re: SDR Tuning Knob

Posted: Mon Jan 22, 2018 10:44 pm
by WeakSingal3o3
Love it! :ugeek: I'll have to get a few of those boards ordered. I love the fact one can create so much with todays gadgets.. I see people doing stuff with Arduino and radio that years back we would have expected to have a engineer designing it and now everyday people can create amazing things in their own home. Specially with 3d printing and home cnc machines and the like. Very exciting time to be alive :)

Re: SDR Tuning Knob

Posted: Thu Jan 25, 2018 11:01 am
by gm4cid
Mike,
I got this working September 2016 and have the working Trinket code, will send by Messenger.

73,

Bob GM4CID

Re: SDR Tuning Knob

Posted: Sat Jan 27, 2018 1:47 pm
by mikexeno
Bob. Do you have my old code or our old code or :) your code. It was so long ago I can't remember.

Re: SDR Tuning Knob

Posted: Tue Jan 30, 2018 11:56 pm
by WeakSingal3o3
Great news :) this forum is wonderful. Such a friendly and supportive group. Can't wait to try this knobs out when I have the code. For short term, and due to cost restrictions lol, I modified a mouse. It works, but not that well.

Anyhow, i thank you both and I hope your week is going well :)


73

Re: SDR Tuning Knob

Posted: Thu Feb 01, 2018 4:32 am
by mikexeno
// Tuner_Knob_Trinket
// Based on Adafruit Volume Control https://learn.adafruit.com/trinket-usb-volume-knob
// and work by Mike KD2KOG
// Modified by GM4CID 2016-09-12

#include "TrinketMouse.h"

#define PIN_ENCODER_A 0
#define PIN_ENCODER_B 2
#define TRINKET_PINx PINB

static uint8_t enc_prev_pos = 0;
static uint8_t enc_flags = 0;

void setup()
{
// set pins as input with internal pull-up resistors enabled
pinMode(PIN_ENCODER_A, INPUT);
pinMode(PIN_ENCODER_B, INPUT);
digitalWrite(PIN_ENCODER_A, HIGH);
digitalWrite(PIN_ENCODER_B, HIGH);

TrinketMouse.begin(); // start the USB device engine and enumerate

// get an initial reading on the encoder pins
if (digitalRead(PIN_ENCODER_A) == LOW) {
enc_prev_pos |= (1 << 0);
}
if (digitalRead(PIN_ENCODER_B) == LOW) {
enc_prev_pos |= (1 << 1);
}
}

void loop()
{
int8_t enc_action = 0; // 1 or -1 if moved, sign is direction

// note: for better performance, the code will now use
// direct port access techniques
// http://www.arduino.cc/en/Reference/PortManipulation
uint8_t enc_cur_pos = 0;
// read in the encoder state first
if (bit_is_clear(TRINKET_PINx, PIN_ENCODER_A)) {
enc_cur_pos |= (1 << 0);
}
if (bit_is_clear(TRINKET_PINx, PIN_ENCODER_B)) {
enc_cur_pos |= (1 << 1);
}

// if any rotation at all
if (enc_cur_pos != enc_prev_pos)
{
if (enc_prev_pos == 0x00)
{
// this is the first edge
if (enc_cur_pos == 0x01) {
enc_flags |= (1 << 0);
}
else if (enc_cur_pos == 0x02) {
enc_flags |= (1 << 1);
}
}

if (enc_cur_pos == 0x03)
{
// this is when the encoder is in the middle of a "step"
enc_flags |= (1 << 4);
}
else if (enc_cur_pos == 0x00)
{
// this is the final edge
if (enc_prev_pos == 0x02) {
enc_flags |= (1 << 2);
}
else if (enc_prev_pos == 0x01) {
enc_flags |= (1 << 3);
}

// check the first and last edge
// or maybe one edge is missing, if missing then require the middle state
// this will reject bounces and false movements
if (bit_is_set(enc_flags, 0) && (bit_is_set(enc_flags, 2) || bit_is_set(enc_flags, 4))) {
enc_action = 1;
}
else if (bit_is_set(enc_flags, 2) && (bit_is_set(enc_flags, 0) || bit_is_set(enc_flags, 4))) {
enc_action = 1;
}
else if (bit_is_set(enc_flags, 1) && (bit_is_set(enc_flags, 3) || bit_is_set(enc_flags, 4))) {
enc_action = -1;
}
else if (bit_is_set(enc_flags, 3) && (bit_is_set(enc_flags, 1) || bit_is_set(enc_flags, 4))) {
enc_action = -1;
}

enc_flags = 0; // reset for next time
}
}

enc_prev_pos = enc_cur_pos;

if (enc_action > 0) {
TrinketMouse.move(0,0,1,0);
}
else if (enc_action < 0) {
TrinketMouse.move(0,0,-1,0);
}
// else {
// TrinketMouse.poll(); // do nothing, check if USB needs anything done
// }
}