s1ck 0 Posted February 28, 2013 Share Posted February 28, 2013 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. Quote Link to post Share on other sites
energia 485 Posted February 28, 2013 Share Posted February 28, 2013 The issue is analog channel 1 (aka A1). Channel A1 maps to pin 3 which is UART TXD as per pin mapping here: https://github.com/energia/Energia/wiki/Hardware. A2 is also a no go since that maps to pin 4 which is UART RXD. Change analogRead(1) to analogRead(3) and you will see that it runs perfectly fine. Quote Link to post Share on other sites
s1ck 0 Posted February 28, 2013 Author Share Posted February 28, 2013 Wow thank you very much, it's working now. I should have guessed that though Quote Link to post Share on other sites
timcastelijn 0 Posted July 9, 2013 Share Posted July 9, 2013 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); } Quote Link to post Share on other sites
L.R.A 78 Posted July 9, 2013 Share Posted July 9, 2013 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 Quote Link to post Share on other sites
spirilis 1,265 Posted July 9, 2013 Share Posted July 9, 2013 Remember A6 and A7... as long as you don't need I2C or SPI communication. Sent from my Galaxy Note II with Tapatalk Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.