9x Analog inputs on Teensy 3.6

Status
Not open for further replies.

Jojamoco

Member
Hello,

I am trying to make a laser "harp" using the teensy by reading some LDR's that have a laser pointed at them. To start I just did the bare bones tutorial #4 reading A0 to check the hardware before carrying on to code(10k ldr in series with 10k resistor dividing 3.3v). Everything worked great, then I copy pasta eight more inputs and everything goes ok but every other read is 0.More specifically A0-A8 read correctly once then on the next sweep they all display 0 then normal then 0 and so on. I tried playing with delays, increasing them, adding them between each read, removing them, etc. same behavior each way. I would be glad for any help as I have never needed to read so many inputs and I certainly have never seen this issue before.

The readings are working and I checked the circuitry it is working if I just use a 3.3v supply and use a meter to check the values.

Here is the code as it is now:

Code:
/* Analog Input Example, Teensyduino Tutorial #4
   http://www.pjrc.com/teensy/tutorial4.html

   After uploading this to your board, use Serial Monitor
   to view the message.  When Serial is selected from the
   Tools > USB Type menu, the correct serial port must be
   selected from the Tools > Serial Port AFTER Teensy is
   running this code.  Teensy only becomes a serial device
   while this code is running!  For non-Serial types,
   the Serial port is emulated, so no port needs to be
   selected.

   This example code is in the public domain.
*/

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

int val[8];

void loop()                     
{
  val[0] = analogRead(0);
  val[1] = analogRead(1);
  val[2] = analogRead(2);
  val[3] = analogRead(3);
  val[4] = analogRead(4);
  val[5] = analogRead(5);
  val[6] = analogRead(6);
  val[7] = analogRead(7);
  val[8] = analogRead(8);  
  
  Serial.print("Analog 0 is: ");
  Serial.println(val[0]);
  //delay(25);  
  Serial.print("Analog 1 is: ");
  Serial.println(val[1]);
  //delay(25);  
  Serial.print("Analog 2 is: ");
  Serial.println(val[2]);
  //delay(25);  
  Serial.print("Analog 3 is: ");
  Serial.println(val[3]);
  //delay(25);
  Serial.print("Analog 4 is: ");
  Serial.println(val[4]);
  //delay(25);
  Serial.print("Analog 5 is: ");
  Serial.println(val[5]);
  //delay(25);
  Serial.print("Analog 6 is: ");
  Serial.println(val[6]);
  //delay(25);
  Serial.print("Analog 7 is: ");
  Serial.println(val[7]);
  //delay(25);  
  Serial.print("Analog 8 is: ");
  Serial.println(val[8]);
  //delay(25);

  delay(1000);
}
 
Quick issue I see is that you're over running your buffer. You declare val to be 8 ints in size, but you're trying to stuff 9 ints in there! You need to declare val to be size 9:
Code:
int val[9];
 
Quick issue I see is that you're over running your buffer. You declare val to be 8 ints in size, but you're trying to stuff 9 ints in there! You need to declare val to be size 9:
Code:
int val[9];

Thank you, this is why you include even simple code. rookie typo. All good now I can move on.

Once again thanks

Jon
 
Status
Not open for further replies.
Back
Top