Sign in to follow this  
Followers 0
morelius21

MPS430F5529L reading multiple potentiometer

5 posts in this topic

Hi

 

i try to read five potentiometer and print this values to serial monitor. I use a for loop but don't work. only work when i use A0, A1,etc.. in analogRead function. Any idea?

 

thanks

/*
  AnalogReadSerial

  Reads an analog input on pin A0 to A4 (P6.0 to P6.4), prints the result to the serial monitor.
  
  
  Hardware Required:
  * MSP-EXP430G2 LaunchPad
  * 10-kilohm Potentiometer
  * hook-up wire

  This example code is in the public domain.
*/

int i = 0;
int sensorValue = 0;

// the setup routine runs once when you press reset:

void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600); // msp430g2231 must use 4800
}

// the loop routine runs over and over again forever:
void loop() {
  // read the input on analog pin A0-A4:
  for (i=0; i < 6; i++){
  sensorValue = analogRead(i);
  Serial.println(sensorValue);
  delay(300); // delay in between reads for stability
  }
}
  

Share this post


Link to post
Share on other sites

Hi @@morelius21

 

You are not reading A0, A1, etc. with your code.  You are reading pin numbers.  See the pin map at http://energia.nu/wordpress/wp-content/uploads/2014/01/MSP430F5529.jpeg

 

In your loop, you are reading pin 0 first (doesn't exist), and then pin 1 (3.3V), etc.  What you should be doing is reading from pin 23 through 27.

dubnet, morelius21 and energia like this

Share this post


Link to post
Share on other sites

Starting point is you have an off by one eror on the loop counter: the test should be "<5", not "<6" as you are trying to do it.

 

But, I think the main issue is that A0, A1, etc are aliases for pin identities, not channel values. You might try:

const int analogpins[]={A0, A1, A2, A3, A4};
.
.
.
.
for (int i=0; i<5; i++) {
   sensorValue=analogRead(analogpins[i]);
      .
      .
      .
energia, dubnet and morelius21 like this

Share this post


Link to post
Share on other sites

hi

 

thanks for all replies, 

 

@Fmilburn: ok i understand but the samme code in arduino uno work well my code, Maybe is coincidence with the pins coincidence i I was lucky

 

@@enl, you are right is i<5, i will yous your array, i find is the clearest way.

 

now the code work well, thanks!

Share this post


Link to post
Share on other sites

Just a note : if you want to directly select a channel of the ADC, add 128 to the pin value.

 

For example, analogRead(128+5) will return the value of the "real' channel 5 of the ADC.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0