Pages: [1]   Go Down
Author Topic: arduino mini & analong pins 6 & 7  (Read 1326 times)
0 Members and 1 Guest are viewing this topic.
New York, NY
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,

I can't seem to get the 7h and 8th analog channels to work.  1-6 are great.  any suggestions??

Thanks,
Willie
Logged

Forum Administrator
Cambridge, MA
Offline Offline
Faraday Member
*****
Karma: 12
Posts: 3538
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Which version of the Arduino software are you using?  Support for the last two analog inputs was only added in Arduino 0006.  Also, the channels are numbered 0 to 7, not 1 to 8.
Logged

New York, NY
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,

Thanks for the reply.  I'm using 0007.  And yes, I'm trying to access inputs 6 & 7 of 0-7.  Here's the code I wrote to create smoothed midi continuous controls from the 8 analog ins.  Analog 0-5 work beautifully.  Any ideas?

Thanks,
Willie

Code:
// Variables:
int LED = 13;
int ANA_AVG_old[8] = {0, 0, 0, 0, 0, 0, 0, 0};
int ANA_AVG_new[8] = {0, 0, 0, 0, 0, 0, 0, 0};

// Functions:

//  compile midi message
void ConC(char cmd, char data1, char data2) {
 Serial.print(cmd, BYTE);
 Serial.print(data1, BYTE);
 Serial.print(data2, BYTE);
}

void setup() {
 //  Set MIDI baud rate:
 Serial.begin(31250);
}

void loop() {

 //Read Analog pins, make a running average, if diff then send values
 int i;
   for (i = 0; i < 8; i++) {

     ANA_AVG_new[i] = (ANA_AVG_old[i] + analogRead(i)) /2;
           if (ANA_AVG_new[i] != ANA_AVG_old[i]) { //if diff do stuff
             ConC(176, i, ANA_AVG_new[i]/8);
             analogWrite(LED, 128);
             delay(10);
             ANA_AVG_old[i] = ANA_AVG_new[i];
           } else { //else if same do less stuff
             analogWrite(LED, 0);
           }
   }

}  //END VOID LOOP
Logged

Forum Administrator
Cambridge, MA
Offline Offline
Faraday Member
*****
Karma: 12
Posts: 3538
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

What do you mean by not working correctly?  What values do you get?  How did you physically connect to the analog inputs?
Logged

New York, NY
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm getting no values at all on the last two.  Physically, I have all 8 inputs connected identically. I'm using a potentiometer to send midi continuous control values from 0-127.  Inputs 0-5 work flawlessly.  But I get absolutely nothing out of 6 & 7.  Is there something different about these last two inputs?  Do they need to be addressed differently? Do they need to be somehow declared/prepped in the void setup()?  I've tried multiple minis in different capacities and have not been able to get anything from inputs 6 & 7 in botth Arduino 0006 and 0007.
« Last Edit: January 15, 2007, 03:21:24 pm by wfastenow » Logged

Florida, USA
Offline Offline
Full Member
***
Karma: 0
Posts: 146
meow!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Which processor are you using?  On the ATmega8, there are only 6 analog input pins: 0..5.
Logged

New York, NY
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thanks for the post.  i'm using the atmega168 with (supposedly) 8 analog ins.

is there anybody who is using the last two analog ins?  it seems like there is something inherently different about AD6 and AD7 based off of my and my associates' trials.  the issue is really perplexing us, as 0-5 work swiftly, and there is nothing shown coming in to 6-7.

best,
willie
Logged

New York, NY
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

replace the pins_arduino.c file with the following code

path is
arduino-0007/lib/targets/arduino/

and pins 6 &7 will work!

Thanks to all who helped.

Best,
Willie


Code:
/*
  pins_arduino.c - pin definitions for the Arduino board
  Part of Arduino / Wiring Lite

  Copyright (c) 2005 David A. Mellis

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General
  Public License along with this library; if not, write to the
  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  Boston, MA  02111-1307  USA

  $Id: pins_arduino.c 191 2006-10-15 11:45:26Z mellis $
*/

#include <avr/io.h>
#include "wiring.h"

// On the Arduino board, digital pins are also used
// for the analog output (software PWM).  Analog input
// pins are a separate set.

// ATMEL ATMEGA8 / ARDUINO
//
//             +-\/-+
//       PC6  1|    |28  PC5 (AI 5)
// (D 0) PD0  2|    |27  PC4 (AI 4)
// (D 1) PD1  3|    |26  PC3 (AI 3)
// (D 2) PD2  4|    |25  PC2 (AI 2)
// (D 3) PD3  5|    |24  PC1 (AI 1)
// (D 4) PD4  6|    |23  PC0 (AI 0)
//       VCC  7|    |22  GND
//       GND  8|    |21  AREF
//       PB6  9|    |20  AVCC
//       PB7 10|    |19  PB5 (D 13)
// (D 5) PD5 11|    |18  PB4 (D 12)
// (D 6) PD6 12|    |17  PB3 (D 11) PWM
// (D 7) PD7 13|    |16  PB2 (D 10) PWM
// (D 8) PB0 14|    |15  PB1 (D 9) PWM
//             +----+

#define NUM_DIGITAL_PINS 14
#define NUM_ANALOG_OUT_PINS 11
#define NUM_ANALOG_IN_PINS 8
#define NUM_PORTS 4

#define PB 2
#define PC 3
#define PD 4

// these arrays map port names (e.g. port B) to the
// appropriate addresses for various functions (e.g. reading
// and writing)
int port_to_mode[NUM_PORTS + 1] = {
      NOT_A_PORT,
      NOT_A_PORT,
      _SFR_IO_ADDR(DDRB),
      _SFR_IO_ADDR(DDRC),
      _SFR_IO_ADDR(DDRD),
};

int port_to_output[NUM_PORTS + 1] = {
      NOT_A_PORT,
      NOT_A_PORT,
      _SFR_IO_ADDR(PORTB),
      _SFR_IO_ADDR(PORTC),
      _SFR_IO_ADDR(PORTD),
};

int port_to_input[NUM_PORTS + 1] = {
      NOT_A_PORT,
      NOT_A_PORT,
      _SFR_IO_ADDR(PINB),
      _SFR_IO_ADDR(PINC),
      _SFR_IO_ADDR(PIND),
};

// these arrays map the pin numbers on the arduino
// board to the atmega8 port and pin numbers
pin_t digital_pin_to_port_array[NUM_DIGITAL_PINS] = {
      { PD, 0 },
      { PD, 1 },
      { PD, 2 },
      { PD, 3 },
      { PD, 4 },
      { PD, 5 },
      { PD, 6 },
      { PD, 7 },
      { PB, 0 },
      { PB, 1 },
      { PB, 2 },
      { PB, 3 },
      { PB, 4 },
      { PB, 5 },
};

pin_t *digital_pin_to_port = digital_pin_to_port_array;

int analog_out_pin_to_timer_array[NUM_DIGITAL_PINS] = {
      NOT_ON_TIMER,
      NOT_ON_TIMER,
      NOT_ON_TIMER,
      // on the ATmega168, digital pin 3 has hardware pwm
#if defined(__AVR_ATmega168__)
      TIMER2B,
#else
      NOT_ON_TIMER,
#endif
      NOT_ON_TIMER,
      // on the ATmega168, digital pins 5 and 6 have hardware pwm
#if defined(__AVR_ATmega168__)
      TIMER0B,
      TIMER0A,
#else
      NOT_ON_TIMER,
      NOT_ON_TIMER,
#endif
      NOT_ON_TIMER,
      NOT_ON_TIMER,
      TIMER1A,
      TIMER1B,
#if defined(__AVR_ATmega168__)
      TIMER2A,
#else
      TIMER2,
#endif
      NOT_ON_TIMER,
      NOT_ON_TIMER,
};

int *analog_out_pin_to_timer = analog_out_pin_to_timer_array;

/*
// Some of the digital pins also support hardware PWM (analog output).
pin_t analog_out_pin_to_port_array[NUM_DIGITAL_PINS] = {
      { NOT_A_PIN, NOT_A_PIN },
      { NOT_A_PIN, NOT_A_PIN },
      { NOT_A_PIN, NOT_A_PIN },
      { NOT_A_PIN, NOT_A_PIN },
      { NOT_A_PIN, NOT_A_PIN },
      { NOT_A_PIN, NOT_A_PIN },
      { NOT_A_PIN, NOT_A_PIN },
      { NOT_A_PIN, NOT_A_PIN },
      { NOT_A_PIN, NOT_A_PIN },
      { PB, 1 },
      { PB, 2 },
      { PB, 3 },
      { NOT_A_PIN, NOT_A_PIN },
      { NOT_A_PIN, NOT_A_PIN },
};

pin_t *analog_out_pin_to_port = analog_out_pin_to_port_array;
*/
pin_t analog_in_pin_to_port_array[NUM_ANALOG_IN_PINS] = {
      { PC, 0 },
      { PC, 1 },
      { PC, 2 },
      { PC, 3 },
      { PC, 4 },
      { PC, 5 },
      { PC, 6 },
      { PC, 7 },
#if defined(__AVR_ATmega168__)
  { NOT_A_PIN, 6 },
  { NOT_A_PIN, 7 },
#endif
};

pin_t *analog_in_pin_to_port = analog_in_pin_to_port_array;
« Last Edit: January 17, 2007, 12:53:15 am by wfastenow » Logged

Forum Administrator
Cambridge, MA
Offline Offline
Faraday Member
*****
Karma: 12
Posts: 3538
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Whoops.  That's what I get for not soldering some wires to my Mini and testing my code!  I'll fix this in Arduino 0008.

You just changed this line, right?

Code:
#define NUM_ANALOG_IN_PINS 8
« Last Edit: January 17, 2007, 03:17:52 am by mellis » Logged

New York, NY
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

yep! that's the one.  also, make sure the end of the file looks like the below  (that { PC, 6 }, and { PC, 7 }, are included, etc.

best,
willie

Code:
pin_t *analog_out_pin_to_port = analog_out_pin_to_port_array;
*/
pin_t analog_in_pin_to_port_array[NUM_ANALOG_IN_PINS] = {
      { PC, 0 },
      { PC, 1 },
      { PC, 2 },
      { PC, 3 },
      { PC, 4 },
      { PC, 5 },
      { PC, 6 },
      { PC, 7 },
#if defined(__AVR_ATmega168__)
  { NOT_A_PIN, 6 },
  { NOT_A_PIN, 7 },
#endif
};

pin_t *analog_in_pin_to_port = analog_in_pin_to_port_array;
Logged

Forum Administrator
Cambridge, MA
Offline Offline
Faraday Member
*****
Karma: 12
Posts: 3538
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Are you sure it doesn't work if you remove these two lines?

Code:
     { PC, 6 },
      { PC, 7 },
Logged

New York, NY
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

actually, no, i didn't check it out with those lines removed...  maybe it does.  i'll test it out tonight.
Logged

Toronto, Ontario
Offline Offline
Newbie
*
Karma: 0
Posts: 23
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

willie, you rock.

I have a question. Have you successfully managed to get the extra pins to work with Max/MSP yet?

(because I haven't...  smiley-sad )
Logged

-Scott

Pages: [1]   Go Up
Jump to: