Reading multiple FSRs?

Forgive quite possibly daft questions as I'm a noobie :slight_smile: I can see plenty of code to read one FSR and wiring diagrams for multiples. I have looked at various posts re this question but can't find any successful code for what I hope to do, i.e. read 5 FSRs simultaneously. Also, some posts are years old and I didn't want to raise the long dead.

My requirement is more for obtaining rough percentage load distribution than exact weight values and the loading wouldn't change much during a single test, e.g. 10% on each of FSRs 1-4 and 60% on FSR5. Happy to get the data in any format as I can figure out how to convert it to %, kg or whatever.

Is it simply a question of duplicating the code and incrementing to FSR's pin number by 1 till I reach 5? From what I have read, there are much more elegant ways but I'm not sure I'm ready for anything other than quick'n'dirty methods. That said, I'd be happy to try if it could be explained in terms Homer Simpson would understand :slight_smile:

If there are any examples of similar routines that could be adapted (easily) or a link to a tutorial I'd be grateful.

That's never going to happen with a single-core MCU.

One analogRead takes about 0.1ms on a common Uno, so five sensors could be read in 0.5ms.
Is that simultaneously enough?
Leo..

Thanks, that's more than simultaneously enough for me :slight_smile: Would that mean that they blinked on/off in turn or just refreshed the display every 0.5ms? Either way would achieve my purpose.

The refreshing of the display is entirely up to you and your program. Usually people refresh a display only when a particular value changes and then ONLY the part that has changed,

Refreshing complex values on a display more than four times per second (250ms) is not recommended. Because humans can't process much faster than that.
Leo..

TBH, milliseconds aren't the issue. I don't care if they update every 10 or 20 seconds. My issue is the really basic one of reading 5 sensors and displaying the results so I can see all 5 values at once (what I meant by simultaneously). I'm that much of a noob!

A noob would first use one FSR, and try to display it's A/D value on the serial monitor,
before thinking of up-scaling to five FSRs.
Leo..

Hello
Do not multiply the code.
Build an object, containing all relevant data, and a method or service to use this data for proccesing, instead.
Have a nice day and enjoy coding in C++.

That's what I plan to do and have copious examples to work from. It's the next next step that I need help with.

Objects? Data services? Homer Simpson is baffled :thinking:

Hello esinem
The magic word is OOP.

Have a nice day and enjoy coding in C++.

Thanks. My dear old mum said it was 'Please' :smiley: Anyway, found this, will have a play: Arduino Object Oriented Programming (OOP) - The Robotics Back-End (roboticsbackend.com)

One way to read the five analog input pins and store the five analog values in five integers for later processing is to use parallel arrays:

const size_t PinCount = 5;
const byte FSRPins[PinCount] = {A0, A1, A2, A3, A4};

void loop()
{
  int FSRValues[PinCount];
  for (size_t i = 0; i < PinCount; i++)
  {
    FSRValues[i] = analogRead(FSRPins[i]);
  }

  // Now you have all the data and you can do
  // whatever you want with it.
}
1 Like

That looks super-helpful. Dumb question: Will that give me the data for each FSR in FSRValues 1 through 5?

It will be ages before my FSRs arrive so I will have to see if I can substitute variable resistors of some kind so I can play with the code.

I can see I will have to delve a lot deeper into the coding side as it doesn't seem anyone can point me to an existing project I can tweak. I foresee more error than trial :smiley:

Thatยดs the best way to learn

Arrays start with element zero so a 5-element array has elements 0, 1, 2, 3, and 4. The data for the first pin listed in the array goes into FSRValues[0] and the last pin listed goes into FSRValues[PinCount-1].

Thanks. Yes, just watched a tutorial explaining the 0 start and about arrays. I'm learning slowly :grinning:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.