Another Modified PGA2311 kit with Arduino for volume control and input selection - Page 2 - diyAudio
Go Back   Home > Forums > Source & Line > Analog Line Level

Analog Line Level Preamplifiers , Passive Pre-amps, Crossovers, etc.

Please consider donating to help us continue to serve you.

Ads on/off / Custom Title / More PMs / More album space / Advanced printing & mass image saving
Reply
 
Thread Tools Search this Thread
Old 16th August 2014, 11:49 PM   #11
diyAudio Member
 
Join Date: Mar 2007
Location: Bandung
Those remote are apple ir remote, i saw on ebay $20
__________________
Didiet
WM8805+ESS9023 / SDHC Card I2S audio player + AK4430
  Reply With Quote
Old 17th August 2014, 12:33 AM   #12
cjkpkg is offline cjkpkg  United States
diyAudio Member
 
Join Date: Aug 2008
Location: Roswell GA
Its an Apple remote. Pretty slick and what inspired me to take on this project.
  Reply With Quote
Old 17th August 2014, 12:06 PM   #13
cjkpkg is offline cjkpkg  United States
diyAudio Member
 
Join Date: Aug 2008
Location: Roswell GA
Code:
#include <IRremote.h>

int RECV_PIN = 6;
int relay1 = 2;
int relay2 = 3;
int relay3 = 4;

int on = 0;
int on1 = 0;
int on2 = 0;
int on3 = 0;

IRrecv irrecv(RECV_PIN);
decode_results results;

void setup()
{
  pinMode(relay3, OUTPUT);
  pinMode(relay2, OUTPUT);
  pinMode(relay1, OUTPUT);
  pinMode(13, OUTPUT);
  irrecv.enableIRIn(); // Start the receiver
}

unsigned long last = millis();

void loop() {
  if (irrecv.decode(&results))
  {
    if (results.value == 2011254788) 
    { // Remote Control Power Code
      // If it's been at least 1/4 second since the last
      // IR received, toggle the relay
      if (millis() - last > 250) 
      {
        on = !on;
        digitalWrite(relay1, on ? HIGH : LOW);
      }
      last = millis();
    }    

    else if (results.value == 2011258884) 
    {
      if (millis() - last > 250) 
      {
        on1 = !on1;
        digitalWrite(relay2, on1 ? HIGH : LOW);
      }
      last = millis();
    }

    else if (results.value == 2011246596) 
    {
      if (millis() - last > 250) 
      {
        on2 = !on2;
        digitalWrite(relay3, on2 ? HIGH : LOW);
      }
      last = millis();

    }

    irrecv.resume(); // Receive the next value
  }
}
OK I tried this bit of code out with the addition of my apple remote up, right, and down code and I was successfully able to switch between relays, but what I want to do is scroll through the inputs only using the left and right buttons on the remote.

Getting closer, any advice or suggestions on tweaking this bit of code is appreciated.

Code:
UP	 77E15004 	2011254788
DOWN	 77E13004	2011246596
LEFT 	77E19004	2011271172
RIGHT 	77E16004	2011258884
CENTER	 77E13A04 77E1A004	2011249156
MENU 	77E1C004	2011283460
PLAY/PAUSE	 77E1FA04 77E1A004	2011298308
  Reply With Quote
Old 18th August 2014, 08:07 PM   #14
diyAudio Member
 
ElectroNick's Avatar
 
Join Date: Dec 2002
Location: The Netherlands
Ehh, a little error from my side....
Interrupt 0 and 1 are not on Pin 0 & 1

But on pin 2 & 3.
But this is no problem regarding the number of pins, you still have enough of 'em.

Regards,
Nick
__________________
BOZ & A40
  Reply With Quote
Old 18th August 2014, 08:33 PM   #15
cjkpkg is offline cjkpkg  United States
diyAudio Member
 
Join Date: Aug 2008
Location: Roswell GA
OK making a little more progress...

Working:
  • So far I changed the welcome message
  • I got rid of the volume bar thing that didnt display right
  • On the remote the left button toggles the input 1 on/off
  • The right button toggles input 2 on/off
  • The top button is volume up
  • Bottom button is volume down

Still need to fix:
  • On the display I tried to get it to display which input is active to the right of the startup message. The input shows and stays on until you adjust the volume and it goes away.
  • The ability to scroll through the inputs just by pressing left or right buttons
  • Add a mute function by pressing play/pause - just need to assign function to button and pin on arduino board
  • Need to add encoder

Here is the latest functioning code:
Code:
/*
 Arduino pins:
 - digital pin 13 (SCK) = SPI SCLK (PGA2311 pin 6)
 - digital pin 12 (MISO) = not used
 - digital pin 11* (MOSI) = SPI SDI/MOSI (PGA2311 pin 3)
 - digital pin 10* (SS) = SPI \CS (PGA2311 pin 2)
 - digital pin 6* = IR receiver data
 - digital pin 1 = not connected
 - digital pin 0 = not connected
 * is a PWM pin
 
/*-----( Import needed libraries )-----*/
#include <Wire.h>  // Comes with Arduino IDE
// Get the LCD I2C Library here: 
// https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads
// Move any other LCD libraries to another folder or delete them
// See Library "Docs" folder for possible commands etc.
#include <LiquidCrystal_I2C.h>
#include <IRremote.h>
#include <stdlib.h>
#include <SPI.h>

/*-----( Declare Constants )-----*/
/*-----( Declare objects )-----*/
// set the LCD address to 0x27 for a 20 chars 4 line display
// Set the pins on the I2C chip used for LCD connections:
//                    addr, en,rw,rs,d4,d5,d6,d7,bl,blpol
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address

/*-----( Declare Constants )-----*/
#define RELAY_ON 0
#define RELAY_OFF 1
/*-----( Declare objects )-----*/
/*-----( Declare Variables )-----*/
#define Relay_1  2  // Arduino Digital I/O pin number
#define Relay_2  3
#define Relay_3  4

/*IR detector data=pin 6

* PGA2311 gain:  
N = 1 to 255
* Gain (dB) = 31.5-[0.5*(255-N)]

* SPI interface:
* /CS (pin 2) 
* SCLK (pin 6)
* SDI (pin 3)
* SDO (pin 7)

*/

const int slaveSelectPin = 10;
int RECV_PIN = 6;
IRrecv irrecv(RECV_PIN);
decode_results results;
String lastIRoperation;
int relay1 = 2;
int relay2 = 3;

int on = 0;
int on1 = 0;
int on2 = 0;

char cGain[17];
String gain;
char icGain[6];
float iGain = -95.5;
float nGain = 1;


void setup() {
  Serial.begin(9600);  // Used to type in characters

  lcd.begin(16,2);   // initialize the lcd for 16 chars 2 lines, turn on backlight
  lcd.write("CJ's Preamp ");

  irrecv.enableIRIn();

  pinMode(slaveSelectPin, OUTPUT);
  SPI.begin(); 
  
  //-------( Initialize Pins so relays are inactive at reset)----
  digitalWrite(Relay_1, RELAY_ON);
  digitalWrite(Relay_2, RELAY_OFF);
  
//---( THEN set pins as outputs )----  

  pinMode(relay2, OUTPUT);
  pinMode(relay1, OUTPUT);
 
  delay(4000); //Check that all relays are inactive at Reset


}
int VolumeUp() {
    if (nGain < 255) {  
      nGain = nGain + 1;
      setGain(nGain);
      setVolumeBar(nGain);
    }
    else {
      lcd.setCursor(0, 0);
      lcd.write("Maximum Reached");
      delay(500);
    }
}  
int VolumeDown() {
    if (nGain > 1) {
      nGain = nGain - 1;
      setGain(nGain);
      setVolumeBar(nGain);
    }
    else {
      lcd.setCursor(0,0);
      lcd.write("Minimum Reached ");
      delay(500);     
    }
}

void setGain(int nGain) {
  digitalWrite(slaveSelectPin,LOW);
  SPI.transfer(nGain);  // right channel
  SPI.transfer(nGain);  // left channel
  digitalWrite(slaveSelectPin,HIGH);
}

void setVolumeBar(int nGain) {
  // convert gain to a decibal string, and write to the lcd
  iGain = 31.5 - 0.5*(255 - float(nGain));       
  gain.toCharArray(icGain, 6);
  dtostrf(iGain,4,1,icGain);
  gain = String(icGain);
  lcd.clear();
  lcd.write("CJ's Preamp ");
  ("Volume: " + gain + " dB").toCharArray(cGain,17);
  lcd.setCursor(0, 1);  //first line
  lcd.write(cGain);
  // write the volume bar
    }


unsigned long last = millis();

void loop() {
  // Decode the IR if recieved
  if (irrecv.decode(&results)) {
    if(results.value == 2011254788) {
      lastIRoperation = "volumeUp";
      VolumeUp();
    }
    if(results.value == 2011246596) {
      lastIRoperation = "volumeDown";
      VolumeDown();
    }
       if (results.value == 2011271172) 
    { // Remote Control Power Code
      // If it's been at least 1/4 second since the last
      // IR received, toggle the relay
      if (millis() - last > 250) 
      {
        on = !on;
        digitalWrite(relay1, on ? HIGH : LOW);
          lcd.setCursor(13,0); //Start at character 13 on line 0
          lcd.print("IN1");
      }
      last = millis();
    }    

    else if (results.value == 2011258884) 
    {
      if (millis() - last > 250) 
      {
        on1 = !on1;
        digitalWrite(relay2, on1 ? HIGH : LOW);
          lcd.setCursor(13,0); //Start at character 13 on line 0
          lcd.print("IN2");
      }
      last = millis();
    }
    if(results.value == 4294967295) {
      if (lastIRoperation == "volumeUp") { VolumeUp(); }
      if (lastIRoperation == "volumeDown") { VolumeDown(); }
    }
    irrecv.resume(); // Receive the next value
  }

}
  Reply With Quote
Old 18th August 2014, 09:32 PM   #16
diyAudio Member
 
Bob Richards's Avatar
 
Join Date: Feb 2011
Location: Portland Oregon, USA
It occurred to me that I'd rather use my smart phone for a remote for my stereo than a separate dedicated remote. Now days virtually everyone has a smartphone by their side. Just need to find someone who can write the application, and create the receiving end interface. I'd want input selection, volume, mute, a few tone options, maybe an external processor in/out option and that's about it. Any thoughts?
  Reply With Quote
Old 18th August 2014, 11:33 PM   #17
cjkpkg is offline cjkpkg  United States
diyAudio Member
 
Join Date: Aug 2008
Location: Roswell GA
Like this

Seems like this would be a start.
  Reply With Quote
Old 19th August 2014, 02:50 AM   #18
diyAudio Member
 
Bob Richards's Avatar
 
Join Date: Feb 2011
Location: Portland Oregon, USA
Quote:
Originally Posted by cjkpkg View Post
Like this

Seems like this would be a start.
Yes. Thankyou.
  Reply With Quote
Old 20th August 2014, 02:07 PM   #19
diyAudio Member
 
Join Date: Aug 2009
Location: Smederevo, Serbia
Maybe this blog from my friend FarmTech will be helpful for you:
http://blog.royalsystems.dk/#post26
  Reply With Quote
Old 24th August 2014, 08:42 PM   #20
cjkpkg is offline cjkpkg  United States
diyAudio Member
 
Join Date: Aug 2008
Location: Roswell GA
Allright...

not my best work but the PGA and Arudino is inside the Aikido. I need to clean up some wiring and the LCD window but she is working.

Both remote and encoder change volume

Need to fix
Save settings
Scroll Inputs
Display Input after volume adjust

Click the image to open in full size.
  Reply With Quote

Reply


Hide this!Advertise here!
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Building a complete Preamp with an Arduino, remote, volume and input control maxw Analog Line Level 103 10th September 2014 05:40 AM
PGA2311 volume control. ian332isport Analog Line Level 4 1st May 2014 10:08 PM
PGA2311 + ATMEGA8 VOLUME CONTROL jash2008 Digital Line Level 9 3rd May 2013 09:31 AM
PGA2311 LCD Volume Remote Control+GOLD RCA Jeff Rowland another_bob Analog Line Level 4 14th November 2012 09:35 AM
Input selection and volume control with balanced output, transportable? jmaurer Solid State 0 11th August 2007 07:08 AM


New To Site? Need Help?

All times are GMT. The time now is 03:39 AM.


vBulletin Optimisation provided by vB Optimise (Pro) - vBulletin Mods & Addons Copyright © 2014 DragonByte Technologies Ltd.
Copyright 1999-2014 diyAudio

Content Relevant URLs by vBSEO 3.3.2