Jump to content
43oh

MPS430F5529L reading multiple potentiometer


Recommended Posts

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
  }
}
  
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.

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]);
      .
      .
      .
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!

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...