Go Down

Topic: > 1 analogRead / analogWrite on Due (Read 756 times) previous topic - next topic

gpud

having successfully had an LDR (with fading led reading the LDR values) a 100K VR and 10KVR + MPU9150 raw data on x, y,z axis (euler angles) over serial from a Due board to Processing, i had to reinstall my OS since then i have had this problem.........

I had been using 3.3V direct to mpu9150  and used the 5V to a breadboard from which i ran the analog inputs. I now realize that this could have damaged the Due chip. But, i tested each of the Analog pins I'd been using and individually they were all fine. However, if i use more than one VR, or one VR and the LDR, only one of them works. I have double, triple tested the code and  have now moved the 'analogRead and analogWrite (PWM) for the leds' into  separate sketches for testing. I am attaching the last test sketch version i have tried. However, the error is the same on all the sketches - whereas, with identical code previously, i had no problems with this at all (using them as a help reference for graphical representation) -  Now, i have spent almost 2 days trying work out where/how/why the debug readings in the serial monitor, change on both pins readings for the A0 values i.e. on the A1 input analogRead too (or if i try a different one, the same thing). The led also fades with the value of A0, when it is instructed to respond to the other analog input - which doesnt respond to anything.

I have tested the pots, the pins, the LEDs, the connectors. I have also used two different breadboards - i moved breadboards initially but at the moment cant think what else could be wrong.

I have got the instructions in a separate function - but even if i put all the code in the loop function - the same thing happens.

as you can no doubt tell, i am very new to Arduino and would really appreciate some help as I'm baffled
(aslo i'm using floats, as i had all values going to processing and it was easier to use one value data type when splitting the string and converting)
Code: [Select]



//the A0 LDR works with a calibration sketch etc so i've left it out in this version
// const int sensLDRPin = A0;       // pin that the LDR is attached to
//const int ledLDRPin = 9;           // pin that the Red LED is attached to

const int VRhunkPin = A1;
const int ledVRhkPin = 10;

const int VRtenkiPin = A2;
const int ledVRtkiPin = 11;

float sensVRhunkValue;
float VRhunkvoltage;

float sensVRtenkiValue;
float VRtenkivoltage;
// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
  pinMode(ledVRhkPin, OUTPUT);
  pinMode(ledVRtkiPin, OUTPUT);
  digitalWrite(ledVRhkPin,LOW);  //keep leds down on start up
  digitalWrite(ledVRtkiPin,LOW); //keep leds down on start up
}

// the loop routine runs over and over again forever:
void loop() {
readVRs();
  // print out the value you read:
  Serial.print(sensVRhunkValue);
  Serial.print(": ");
  Serial.print(VRhunkvoltage);
  Serial.print(".  ");
  Serial.print(sensVRtenkiValue);
  Serial.print(": ");
  Serial.print(VRtenkivoltage);
  Serial.println(".  ");
}

void readVRs()
{
    // read the input on analog pin A1:
  sensVRhunkValue = analogRead(VRhunkPin);
  // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
  VRhunkvoltage = sensVRhunkValue * (3.3 / 1023.0);
 
  analogWrite(ledVRhkPin, sensVRhunkValue); 
 
     // read the input on analog pin A2:
  sensVRtenkiValue = analogRead(VRtenkiPin);
  // Convert the analog reading to 0 - 3.3V
  VRtenkivoltage = sensVRtenkiValue * (3.3 / 1023.0);
 
  analogWrite(ledVRtkiPin, sensVRtenkiValue); 
 
}

MarkT

Sounds like the known bug in 1.5.5 with analogRead from more than one pin, either revert to 1.5.3 or download overnight builds.
[ I won't respond to messages, use the forum please ]

gpud

thank you  SO MUCH for letting me know - it's mad cos from oct'13 to jan'14 i'll have to go back to the last version of both Processing and Arduino - thank you!

Go Up