Jump to content
43oh

Serial Problems - ParseInt / available not working


Recommended Posts

Hi

 

When trying to run following code, I can send the first integer "1" but if I continue after that, it just doesnt send anything back.

However, with an Arduino UNO this code works 100%. How can I fix that?

I hope somebody can try that for me, so I can confirm that it's the hardware/library and not the code.

 

void setup()
{
  Serial.begin(9600);
}

void loop()
{
  if( Serial.available() > 0 )
  {
    int inc = Serial.parseInt();
    if(inc == 1)
    {
      int temp = analogRead(0);
      int pressure = analogRead(1);
      
      String t_str = String(temp);
      String p_str = String(pressure);
      String string = t_str + "#" + p_str + ".";
      Serial.println(string);
    }
  }
}

Thanks in advance.

Link to post
Share on other sites
  • 4 months later...

Hi Energia, S1ck,

 

does this mean it is not possible to read 6 analog inputs and send over serial, when hardware UART is enabled?

 

I try to read 6 potmeter-values using the code below, but when R=0 or R=? at A2 the Serial output stops (i.e no new lines appear).  Do you have any suggestions how to work around this?


void setup() {
  Serial.begin(9600); // msp430g2231 must use 4800
  
  pinMode(A0, INPUT);
  pinMode(A1, INPUT);
  pinMode(A2, INPUT);
  pinMode(A3, INPUT);
  pinMode(A4, INPUT);
  pinMode(A5, INPUT);
}

void loop() {
  int sensorValue0 = analogRead(A0);
  delay(20);
  int sensorValue1 = analogRead(A1);
  delay(20);
  int sensorValue2 = analogRead(A2);
  delay(20);
  int sensorValue3 = analogRead(A3);
  delay(20);
  int sensorValue4 = analogRead(A4);
  delay(20);
  int sensorValue5 = analogRead(A5);

  
  delay(40);
   
  Serial.print(sensorValue0);
  Serial.print(" ");
  Serial.print(sensorValue1);
  Serial.print(" ");
  Serial.print(sensorValue2);
  Serial.print(" ");
  Serial.print(sensorValue3);
  Serial.print(" ");
  Serial.print(sensorValue4);
  Serial.print(" ");
  Serial.println(sensorValue5);
}
Link to post
Share on other sites

 

Hi Energia, S1ck,

 

does this mean it is not possible to read 6 analog inputs and send over serial, when hardware UART is enabled?

 

I try to read 6 potmeter-values using the code below, but when R=0 or R=? at A2 the Serial output stops (i.e no new lines appear).  Do you have any suggestions how to work around this?


void setup() {
  Serial.begin(9600); // msp430g2231 must use 4800
  
  pinMode(A0, INPUT);
  pinMode(A1, INPUT);
  pinMode(A2, INPUT);
  pinMode(A3, INPUT);
  pinMode(A4, INPUT);
  pinMode(A5, INPUT);
}

void loop() {
  int sensorValue0 = analogRead(A0);
  delay(20);
  int sensorValue1 = analogRead(A1);
  delay(20);
  int sensorValue2 = analogRead(A2);
  delay(20);
  int sensorValue3 = analogRead(A3);
  delay(20);
  int sensorValue4 = analogRead(A4);
  delay(20);
  int sensorValue5 = analogRead(A5);

  
  delay(40);
   
  Serial.print(sensorValue0);
  Serial.print(" ");
  Serial.print(sensorValue1);
  Serial.print(" ");
  Serial.print(sensorValue2);
  Serial.print(" ");
  Serial.print(sensorValue3);
  Serial.print(" ");
  Serial.print(sensorValue4);
  Serial.print(" ");
  Serial.println(sensorValue5);
}

I sugest using a multiplexer. Using 3 digital ports i belive you can control the multiplexer. Then you read each analog input in 1 analog port, for example. Just not at the same time but each one in short intervals

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