Reading data from an analogue input

Hi,

I have 96 sensors that are serially being fed into an analogue input (A0). I want to read each sample on a clock pulse (A1) when the clock goes high. I then need to display each of the 96 samples on the serial monitor and start again

I understand the basics, such as how to read the serial input and display the value in the serial monitor, but I am also new to the coding and any help would be appreciated :slight_smile:

I am struggling on how to read and display all 96 samples on a clock pulse.

Note: The clock pulse and sample data timings are in sync from the source.

Thanks.

I am struggling on how to read and display all 96 samples on a clock pulse.

How fast are these samples coming in and what serialises them into the one analogue input?

Basically the program holds in a loop until it sees the clock signal make a transition and then it performs the analogue read. You are best storing the results in an array before printing them out as printing might take more time than you have between the samples.

The timing for these samples coming in can be adjusted to suit, but at the moment a clock period is 60ms, so reading a sample during the 30ms high pulse. This can be slowed down though.

The serial analogue source is a single op-amp!

Could you provide any example code on how to store the 96 analogue sample values into an array and then display when all are in?

Thanks :slight_smile:

Well just off the top of my head this is what you need to do.

int samples[96]; // place to put the samples
int clockPin = 5; // or what ever pin the clock comes in on

void loop(){
 for(int i=0; i<96; i++){
   while(digitalRead(clockPin) == LOW) { } // do nothing until the clock is high
   samples[i] = analogRead(0);
   while(digitalRead(clockPin) == HIGH) { } // do nothing until the clock is low
 }
 for(int i=0; i<96; i++){
  Serial.println(samples[i]);
  }
 }

Hi, that's great and makes sense, so I will give it a try :slight_smile:

Hi,

I can read in the incoming analogue data and store it into an array, but all the data is the same, whereas, I want to capture each sample on a clock low input, so 96 clock pulses with 96 samples stored. Here's my code so far...

void loop() {
// Read in samples, store in an array and then display
for(int i = 1; i < 97; i ++) {
while(analogRead(clockInPin) < 100) { // read data while the clock is low
samples = analogRead(dataPin); }

  • while(analogRead(clockInPin) > 800) { } // do nothing until the clock is high*
  • }*
  • for(int i = 1; i < 97; i ++) {*
  • Serial.print(i);*
  • Serial.print(" ");*
    _ Serial.print(samples*);_
    _
    }*_
    Thanks.

If you post code in code tags, you don't get the italics, and the code starts to make sense when others read it.

Arrays start at 0, not 1.

First post says clock high

I want to read each sample on a clock pulse (A1) when the clock goes high.

Last post says clock low

I want to capture each sample on a clock low input

If it's the latter then just swap the HIGH & LOW in Mike's code.

but all the data is the same,

Yes that is why I asked you :-

what serialises them into the one analogue input?